summaryrefslogtreecommitdiffstats
path: root/examples/widgets/doc/src
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2022-12-07 15:31:05 +0100
committerEirik Aavitsland <eirik.aavitsland@qt.io>2022-12-12 12:33:20 +0100
commit4a5abfcea4ec2e494efd117d278a929f020816c0 (patch)
treebc0bc905894d74fe9a509a7f9b44920bb7992368 /examples/widgets/doc/src
parent6a3627b6c5aa5109a80024f3d7b0f938504f7ffe (diff)
wiggly example: add support for emojis etc. (utf16 surrogate pairs)
The venerable wiggly example was created before unicode support was added to Qt. Hence, when extracting the individual characters from the string for painting, the code was not prepared to handle that some characters, like emojis, are composed of two QChar elements. Fixes: QTBUG-28853 Change-Id: I9804415f92775e2b78fa9fcaf7a2d112153cdce0 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'examples/widgets/doc/src')
-rw-r--r--examples/widgets/doc/src/wiggly.qdoc13
1 files changed, 8 insertions, 5 deletions
diff --git a/examples/widgets/doc/src/wiggly.qdoc b/examples/widgets/doc/src/wiggly.qdoc
index 2c7ea5db9e..30a2a34f1b 100644
--- a/examples/widgets/doc/src/wiggly.qdoc
+++ b/examples/widgets/doc/src/wiggly.qdoc
@@ -52,7 +52,7 @@
{QLineEdit::textChanged()}{textChanged()} signal to the wiggly
widget's \c setText() slot to obtain the real time interaction
with the wiggly widget. The widget's default text is "Hello
- world!".
+ world!", with an emoji thrown in for fun.
\section1 WigglyWidget Class Definition
@@ -115,13 +115,16 @@
Each time the \c paintEvent() function is called, we create a
QPainter object \c painter to draw the contents of the widget.
- For each character in \c text, we determine the color and the
- position on the wiggly line based on \c step. In addition, \c x
- is incremented by the character's width.
+ Since we are going to paint the character symbols individually, we
+ extract the unique unicode code point for each character from \c
+ text, and convert it to a string \c symbol. For each \c symbol, we
+ determine the color and the position on the wiggly line based on
+ \c step and its \c offset from the start of the text. In addition,
+ \c x is incremented by the symbol's width.
For simplicity, we assume that QFontMetrics::horizontalAdvance(\c text)
returns the sum of the individual character advances
- (QFontMetrics::horizontalAdvance(\c text[i])). In practice, this is not
+ (QFontMetrics::horizontalAdvance(\c symbol)). In practice, this is not
always the case because QFontMetrics::horizontalAdvance(\c text) also takes
into account the kerning between certain letters (e.g., 'A' and
'V'). The result is that the text isn't perfectly centered. You