FontMetrics QML Type | Qt Quick (original) (raw)

Provides metrics for a given font. More...

Import Statement: import QtQuick

Properties

Methods

Detailed Description

FontMetrics calculates the size of characters and strings for a given font.

It provides a subset of the C++ QFontMetricsF API, with the added ability to change the font that is used for calculations via the font property.

FontMetrics { id: fontMetrics font.family: "Arial" }

Rectangle { width: fontMetrics.height * 4 height: fontMetrics.height * 2 }

See also QFontMetricsF and TextMetrics.

Property Documentation

ascent : real [read-only]

averageCharacterWidth : real [read-only]

capitalHeight : real [read-only, since 6.9]

Returns the capital height as specified by the font.

The cap-height of a font is defined as the height of a capital letter above the baseline. It specifically refers to the height of capital letters that are flat - such as H or I - as opposed to round letters such as O, or pointed letters like A, both of which may display overshoot.

This property was introduced in Qt 6.9.

See also QFontMetricsF::capHeight, ascent, descent, height, and xHeight.

descent : real [read-only]

This property holds the font used for the metrics calculations.

height : real [read-only]

leading : real [read-only]

lineSpacing : real [read-only]

lineWidth : real [read-only]

This property holds the width of the underline and strikeout lines, adjusted for the point size of the font.

See also QFontMetricsF::lineWidth().

maximumCharacterWidth : real [read-only]

minimumLeftBearing : real [read-only]

minimumRightBearing : real [read-only]

overlinePosition : real [read-only]

strikeOutPosition : real [read-only]

underlinePosition : real [read-only]

xHeight : real [read-only]

Method Documentation

qreal advanceWidth(string text)

This method returns an elided version of the string (i.e., a string with "..." in it) if the string text is wider than width. Otherwise, returns the original string.

The mode argument specifies the text elide mode; that is, where the ellipsis should appear when displaying text that doesn't fit.

The flags argument is optional and currently only supports Qt::TextShowMnemonic.

This method is offered as an imperative alternative to the elidedText property of TextMetrics.

See also Qt::TextElideMode and QFontMetricsF::elidedText().

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