Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

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

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

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 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().

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded