Obsolete Members for QFontMetricsF

The following members of class QFontMetricsF are obsolete. They are provided to keep old source code working. We strongly advise against using them in new code.

Public Functions

(obsolete) qreal width (const QString & text ) const
(obsolete) qreal width (QChar ch ) const

Member Function Documentation

qreal QFontMetricsF:: width (const QString & text ) const

Returns the width in pixels of the characters in the given text .

Note that this value is not equal to the width returned by boundingRect ().width() because 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 ().

qreal QFontMetricsF:: width ( QChar ch ) const

This is an overloaded function.

Bearings

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