Obsolete Members for QFontMetrics
The following members of class QFontMetrics are obsolete. They are provided to keep old source code working. We strongly advise against using them in new code.
Public Functions
(obsolete) int | charWidth(const QString &text, int pos) const |
(obsolete) int | width(const QString &text, int len = -1) const |
(obsolete) int | width(QChar ch) const |
Member Function Documentation
int QFontMetrics::charWidth(const QString &text, int pos) const
This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.
Returns the width of the character at position pos in the string text.
The whole string is needed, as the glyph drawn may change depending on the context (the letter before and after the current one) for some languages (e.g. Arabic).
This function also takes non spacing marks and ligatures into account.
int QFontMetrics::width(const QString &text, int len = -1) const
This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.
Returns the width in pixels of the first len characters of text. If len is negative (the default), the entire string is used.
Note that this value is not equal to boundingRect().width(); boundingRect() returns a rectangle describing the pixels this string will cover whereas width() returns the distance to where the next string should be drawn.
See also boundingRect().
int QFontMetrics::width(QChar ch) const
This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.
This is an overloaded function.
Returns the logical width of character ch in pixels. This is a distance appropriate for drawing a subsequent character after ch.
Some of the metrics are described in the image to the right. The central dark rectangles cover the logical width() of each character. The outer pale rectangles cover the leftBearing() and rightBearing() of each character. Notice that the bearings of "f" in this particular font are both negative, while the bearings of "o" are both positive.
Warning: This function will produce incorrect results for Arabic characters or non-spacing marks in the middle of a string, as the glyph shaping and positioning of marks that happens when processing strings cannot be taken into account. When implementing an interactive text control, use QTextLayout instead.
See also boundingRect().
© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.