- Qt 6.6
- Qt Quick
- QML Types
- PathText
- Qt 6.6.0 Reference Documentation

# PathText QML Type

Defines a string in a specified font. More...

Import Statement: | import QtQuick
Since: | QtQuick 2.15

- List of all members, including inherited members

## Properties

- font.bold : bool
- font.capitalization : enumeration
- font.family : string
- font.features : object
- font.italic : bool
- font.kerning : bool
- font.letterSpacing : real
- font.pixelSize : int
- font.pointSize : real
- font.preferShaping : bool
- font.strikeout : bool
- font.styleName : string
- font.underline : bool
- font.weight : int
- font.wordSpacing : real
- text : string
- x : real
- y : real

## Detailed Description

This element defines the shape of a specified string in a specified font. The text's baseline will be translated to the x and y coordinates, and the outlines from the font will be added to the path accordingly.

     PathText {
         x: 0
         y: font.pixelSize
         font.family: "Arial"
         font.pixelSize: 100
         text: "Foobar"
     }

See also Path, QPainterPath::setFillRule, PathPolyline, PathQuad, PathCubic, PathArc, PathAngleArc, PathCurve, PathSvg, and PathMove.

## Property Documentation

font.bold : bool

Sets whether the font weight is bold.

font.capitalization : enumeration

Sets the capitalization for the text.

Constant | Description
--- | ---
`Font.MixedCase` | no capitalization change is applied
`Font.AllUppercase` | alters the text to be rendered in all uppercase type
`Font.AllLowercase` | alters the text to be rendered in all lowercase type
`Font.SmallCaps` | alters the text to be rendered in small-caps type
`Font.Capitalize` | alters the text to be rendered with the first character of each word as an uppercase character
     PathText { text: "Hello"; font.capitalization: Font.AllLowercase }

font.family : string

Sets the family name of the font.

The family name is case insensitive and may optionally include a foundry name, e.g. "Helvetica [Cronyx]". If the family is available from more than one foundry and the foundry isn't specified, an arbitrary foundry is chosen. If the family isn't available a family will be set using the font matching algorithm.

[since 6.6] font.features : object

Applies integer values to specific OpenType features when shaping the text based on the contents in features. This provides advanced access to the font shaping process, and can be used to support font features that are otherwise not covered in the API.

The font features are represented by a map from four-letter tags to integer values. This integer value passed along with the tag in most cases represents a boolean value: A zero value means the feature is disabled, and a non-zero value means it is enabled. For certain font features, however, it may have other intepretations. For example, when applied to the `salt` feature, the value is an index that specifies the stylistic alternative to use.

For example, the `frac` font feature will convert diagonal fractions separated with a slash (such as `1/2`) with a different representation. Typically this will involve baking the full fraction into a single character width (such as `½`).

If a font supports the `frac` feature, then it can be enabled in the shaper as in the following code:

     Text {
         text: "One divided by two is 1/2"
         font.family: "MyFractionFont"
         font.features: { "frac": 1 }
     }

Multiple features can be assigned values in the same mapping. For instance, if we would like to also disable kerning for the font, we can explicitly disable this as follows:

     Text {
         text: "One divided by two is 1/2"
         font.family: "MyFractionFont"
         font.features: { "frac": 1, "kern": 0 }
     }

You can also collect the font properties in an object:

     Text {
         text: "One divided by two is 1/2"
         font: {
             family: "MyFractionFont"
             features: { "frac": 1, "kern": 0 }
         }
     }

Note: By default, Qt will enable and disable certain font features based on other font properties. In particular, the `kern` feature will be enabled/disabled depending on the font.kerning property of the QFont. In addition, all ligature features (`liga`, `clig`, `dlig`, `hlig`) will be disabled if a font.letterSpacing is set, but only for writing systems where the use of ligature is cosmetic. For writing systems where ligatures are required, the features will remain in their default state. The values set using `font.features` will override the default behavior. If, for instance, `"kern"` is set to 1, then kerning will always be enabled, egardless of whether the font.kerning property is set to false. Similarly, if it is set to 0, then it will always be disabled.

This property was introduced in Qt 6.6.

See also QFont::setFeature().

font.italic : bool

Sets whether the font has an italic style.

font.kerning : bool

Enables or disables the kerning OpenType feature when shaping the text. Disabling this may improve performance when creating or changing the text, at the expense of some cosmetic features. The default value is true.

     PathText { text: "OATS FLAVOUR WAY"; font.kerning: false }

font.letterSpacing : real

Sets the letter spacing for the font.

Letter spacing changes the default spacing between individual letters in the font. A positive value increases the letter spacing by the corresponding pixels; a negative value decreases the spacing.

font.pixelSize : int

Sets the font size in pixels.

Using this function makes the font device dependent. Use `pointSize` to set the size of the font in a device independent manner.

font.pointSize : real

Sets the font size in points. The point size must be greater than zero.

font.preferShaping : bool

Sometimes, a font will apply complex rules to a set of characters in order to display them correctly. In some writing systems, such as Brahmic scripts, this is required in order for the text to be legible, but in e.g. Latin script, it is merely a cosmetic feature. Setting the `preferShaping` property to false will disable all such features when they are not required, which will improve performance in most cases.

The default value is true.

     PathText { text: "Some text"; font.preferShaping: false }

font.strikeout : bool

Sets whether the font has a strikeout style.

font.styleName : string

Sets the style name of the font.

The style name is case insensitive. If set, the font will be matched against style name instead of the font properties font.weight, font.bold and font.italic.

font.underline : bool

Sets whether the text is underlined.

font.weight : int

Sets the font's weight.

The weight can be one of:

Constant | Description
--- | ---
`Font.Thin` | 100
`Font.ExtraLight` | 200
`Font.Light` | 300
`Font.Normal` | 400 (default)
`Font.Medium` | 500
`Font.DemiBold` | 600
`Font.Bold` | 700
`Font.ExtraBold` | 800
`Font.Black` | 900
     PathText { text: "Hello"; font.weight: Font.DemiBold }

font.wordSpacing : real

Sets the word spacing for the font.

Word spacing changes the default spacing between individual words. A positive value increases the word spacing by a corresponding amount of pixels, while a negative value decreases the inter-word spacing accordingly.

text : string

The text for which this PathText should contain the outlines.

x : real

The horizontal position of the PathText's baseline.

y : real

The vertical position of the PathText's baseline.

Note: This property refers to the position of the baseline of the text, not the top of its bounding box. This may cause some confusion, e.g. when using the PathText with Qt Quick Shapes. See FontMetrics for information on how to get the ascent of a font, which can be used to translate the text into the expected position.