diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2022-09-08 12:26:03 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2022-09-08 15:38:06 +0200 |
commit | 817f307a18d28143a1e8234f3846d019589c9d7a (patch) | |
tree | bc5da8cb5f5e886a613f3ae28527aa9028802e21 /src/gui/text | |
parent | 2585fa7c091715ba4766bf58a75ae8f632dbb37f (diff) |
doc: Clarify the term advance width
The QFontMetrics documentation has been wrongly stating that the
the horizontalAdvance() gives the width of a string, dating back
to when the function was misnamed as width(). This can cause issues
e.g. when using the value as input to eliding or clipping, since the
advance may be smaller than what is actually drawn.
This tries to clarify the term a bit.
Task-number: QTBUG-90036
Change-Id: I8ed82fa14fe26c2a20cdbee9f2097a0aa4cc3925
Reviewed-by: Lars Knoll <lars@knoll.priv.no>
Diffstat (limited to 'src/gui/text')
-rw-r--r-- | src/gui/text/qfontmetrics.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/gui/text/qfontmetrics.cpp b/src/gui/text/qfontmetrics.cpp index 7997f643ab..7e6af54a56 100644 --- a/src/gui/text/qfontmetrics.cpp +++ b/src/gui/text/qfontmetrics.cpp @@ -75,11 +75,19 @@ extern void qt_format_text(const QFont& font, const QRectF &_r, inFont(). You can also treat the character as a string, and use the string functions on it. - The string functions include horizontalAdvance(), to return the width of a - string in pixels (or points, for a printer), boundingRect(), to - return a rectangle large enough to contain the rendered string, + The string functions include horizontalAdvance(), to return the advance + width of a string in pixels (or points, for a printer), boundingRect(), + to return a rectangle large enough to contain the rendered string, and size(), to return the size of that rectangle. + \note The advance width can be different from the width of the actual + rendered text. It refers to the distance from the origin of the string to + where you would append additional characters. As text may have overhang + (in the case of an italic font for instance) or padding between + characters, the advance width can be either smaller or larger than the + actual rendering of the text. This is called the right bearing of the + text. + Example: \snippet code/src_gui_text_qfontmetrics.cpp 0 |