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) QFontMetricsF(const QFont &font, QPaintDevice *paintdevice)
(obsolete) qreal width(const QString &text) const
(obsolete) qreal width(QChar ch) const

Member Function Documentation

QFontMetricsF::QFontMetricsF(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 QFontMetricsF::QFontMetricsF(const QFont &font, const QPaintDevice *paintdevice)

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.

in Qt 5.11. Use horizontalAdvance() instead.

See also boundingRect() and horizontalAdvance().

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.

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.

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

© 2023 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.