summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhang Hao <zhanghao@uniontech.com>2021-03-29 14:55:14 +0800
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-04-15 01:43:46 +0000
commit78c4d0c48f58854127aa9248f597bf8568f440a1 (patch)
treeec97f8e2cb86681dc4e896fb582c20528d978037
parent1d59fe368a0bd0c04264618e3e6f09d7ce289d33 (diff)
Add new enum value VisualTabCharacter into QChar
With this enumeration value, users can get the width of the current font TAB character more conveniently In addition, added some documentation about where users may use this enumeration. Fixes: QTBUG-92205 Done-with: Volker Hilsheimer <volker.hilsheimer@qt.io> Done-with: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Change-Id: I9794b7553e9299e351f9182de02866d07a1393fc Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r--src/corelib/text/qchar.cpp1
-rw-r--r--src/corelib/text/qchar.h1
-rw-r--r--src/gui/text/qtextlayout.cpp2
-rw-r--r--src/widgets/widgets/qplaintextedit.cpp8
-rw-r--r--src/widgets/widgets/qtextedit.cpp6
5 files changed, 16 insertions, 2 deletions
diff --git a/src/corelib/text/qchar.cpp b/src/corelib/text/qchar.cpp
index dcc36d18ce..7aff25fb4a 100644
--- a/src/corelib/text/qchar.cpp
+++ b/src/corelib/text/qchar.cpp
@@ -595,6 +595,7 @@ QT_BEGIN_NAMESPACE
\value ByteOrderSwapped
\value ParagraphSeparator
\value LineSeparator
+ \value VisualTabCharacter Used to represent a tabulation as a horizontal arrow. Since 6.2.
\value LastValidCodePoint
*/
diff --git a/src/corelib/text/qchar.h b/src/corelib/text/qchar.h
index 78d95e39fa..2a899abf6b 100644
--- a/src/corelib/text/qchar.h
+++ b/src/corelib/text/qchar.h
@@ -98,6 +98,7 @@ public:
ByteOrderSwapped = 0xfffe,
ParagraphSeparator = 0x2029,
LineSeparator = 0x2028,
+ VisualTabCharacter = 0x2192,
LastValidCodePoint = 0x10ffff
};
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index b2b87fb92e..381c1d20ce 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -2617,7 +2617,7 @@ void QTextLine::draw_internal(QPainter *p, const QPointF &pos,
gf.width = iterator.itemWidth;
QPainterPrivate::get(p)->drawTextItem(QPointF(iterator.x.toReal(), y.toReal()), gf, eng);
if (eng->option.flags() & QTextOption::ShowTabsAndSpaces) {
- const QChar visualTab = u'\x2192';
+ const QChar visualTab = QChar(QChar::VisualTabCharacter);
int w = QFontMetrics(f).horizontalAdvance(visualTab);
qreal x = iterator.itemWidth.toReal() - w; // Right-aligned
if (x < 0)
diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp
index 20fdbcd6a8..71aecc4275 100644
--- a/src/widgets/widgets/qplaintextedit.cpp
+++ b/src/widgets/widgets/qplaintextedit.cpp
@@ -2497,7 +2497,13 @@ void QPlainTextEdit::setOverwriteMode(bool overwrite)
\brief the tab stop distance in pixels
\since 5.10
- By default, this property contains a value of 80.
+ By default, this property contains a value of 80 pixels.
+
+ Do not set a value less than the \l {QFontMetrics::}{horizontalAdvance()}
+ of the QChar::VisualTabCharacter character, otherwise the tab-character
+ will be drawn incompletely.
+
+ \sa QTextOption::ShowTabsAndSpaces, QTextDocument::defaultTextOption
*/
qreal QPlainTextEdit::tabStopDistance() const
diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp
index 2d3f98b4b9..55fb8adc5d 100644
--- a/src/widgets/widgets/qtextedit.cpp
+++ b/src/widgets/widgets/qtextedit.cpp
@@ -2066,6 +2066,12 @@ void QTextEdit::setOverwriteMode(bool overwrite)
\since 5.10
By default, this property contains a value of 80 pixels.
+
+ Do not set a value less than the \l {QFontMetrics::}{horizontalAdvance()}
+ of the QChar::VisualTabCharacter character, otherwise the tab-character
+ will be drawn incompletely.
+
+ \sa QTextOption::ShowTabsAndSpaces, QTextDocument::defaultTextOption
*/
qreal QTextEdit::tabStopDistance() const