Obsolete Members for QFontMetricsF | Qt GUI 5.12.9

- Qt 5.12
- Qt GUI
- C++ Classes
- QFontMetricsF
- Qt 5.12.9 Reference Documentation

# 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

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