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) | QFontMetrics(const QFont &font, QPaintDevice *paintdevice) |
(obsolete) int | charWidth(const QString &text, int pos) const |
(obsolete) int | width(QChar ch) const |
(obsolete) int | width(const QString &text, int len = -1) const |
Member Function Documentation
QFontMetrics::QFontMetrics(const QFont &font, QPaintDevice *paintdevice)
This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.
Identical to QFontMetrics::QFontMetrics(const QFont &font, const QPaintDevice *paintdevice)
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(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.
in Qt 5.11. Use horizontalAdvance() instead.
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() and horizontalAdvance().
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.
in Qt 5.11. Use horizontalAdvance() instead.
See also boundingRect() and horizontalAdvance().