- Qt 6.12
- Qt Quick
- QML Types
- TextMetrics
- Qt 6.12.0 Reference Documentation

# TextMetrics QML Type

Provides metrics for a given font and text. More...

Import Statement: | `import QtQuick`

- List of all members, including inherited members

## Properties

- advanceWidth : real
- boundingRect : rect
- elide : enumeration
- elideWidth : real
- elidedText : string
- font : font
- height : real
- renderType : enumeration `(since 6.3)`
- text : string
- tightBoundingRect : rect
- width : real

## Detailed Description

TextMetrics calculates various properties of a given string of text for a particular font.

It provides a declarative API for the functions in QFontMetricsF which take arguments.

     TextMetrics {
         id: textMetrics
         font.family: "Arial"
         elide: Text.ElideMiddle
         elideWidth: 100
         text: "Hello World"
     }

     MyItem {
         text: textMetrics.elidedText
     }

See also QFontMetricsF and FontMetrics.

## Property Documentation

### advanceWidth : real `[read-only]`

This property holds the advance in pixels of the characters in text. This is the distance from the position of the string to where the next string should be drawn.

See also QFontMetricsF::horizontalAdvance().

### boundingRect : rect `[read-only]`

This property holds the bounding rectangle of the characters in the string specified by text.

See also QFontMetricsF::boundingRect() and tightBoundingRect.

### elide : enumeration

This property holds the elide mode of the text. This determines the position in which the string is elided. The possible values are:

Constant | Description
--- | ---
`Qt::ElideNone` | No eliding; this is the default value.
`Qt::ElideLeft` | For example: "...World"
`Qt::ElideMiddle` | For example: "He...ld"
`Qt::ElideRight` | For example: "Hello..."

See also elideWidth and QFontMetrics::elidedText.

### elideWidth : real

This property holds the largest width the text can have (in pixels) before eliding will occur.

See also elide and QFontMetrics::elidedText.

### elidedText : string `[read-only]`

This property holds an elided version of the string (i.e., a string with "..." in it) if the string text is wider than elideWidth. If the text is not wider than elideWidth, or elide is set to `Qt::ElideNone`, this property will be equal to the original string.

See also QFontMetricsF::elidedText().

### font : font

This property holds the font used for the metrics calculations.

### height : real `[read-only]`

This property holds the height of the bounding rectangle of the characters in the string specified by text. It is equivalent to:

     textMetrics.boundingRect.height

See also boundingRect.

### renderType : enumeration `[since 6.3]`

Override the default rendering type for this component.

Supported render types are:

Constant | Description
--- | ---
`TextEdit.QtRendering` | Text is rendered using a scalable distance field for each glyph.
`TextEdit.NativeRendering` | Text is rendered using a platform-specific technique.

This should match the intended `renderType` where you draw the text.

This property was introduced in Qt 6.3.

See also Text.renderType.

### text : string

This property holds the text used for the metrics calculations.

### tightBoundingRect : rect `[read-only]`

This property holds a tight bounding rectangle around the characters in the string specified by text.

See also QFontMetricsF::tightBoundingRect() and boundingRect.

### width : real `[read-only]`

This property holds the width of the bounding rectangle of the characters in the string specified by text. It is equivalent to:

     textMetrics.boundingRect.width

See also boundingRect.