- Qt 6.7
- Qt Quick
- QML Types
- PathText
- Qt 6.7.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 `(since 6.6)`
- 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.variableAxes : object `(since 6.7)`
- 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.

font.features : object `[since 6.6]`

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 interpretations. 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 you would like to also disable kerning for the font, you 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, regardless of whether the font.kerning property is set to false. Similarly, if it is set to `0`, 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.variableAxes : object `[since 6.7]`

Applies floating point values to variable axes in variable fonts.

Variable fonts provide a way to store multiple variations (with different weights, widths or styles) in the same font file. The variations are given as floating point values for a pre-defined set of parameters, called "variable axes". Specific instances are typically given names by the font designer, and, in Qt, these can be selected using setStyleName() just like traditional sub-families.

In some cases, it is also useful to provide arbitrary values for the different axes. For instance, if a font has a Regular and Bold sub-family, you may want a weight in-between these. You could then manually request this by supplying a custom value for the "wght" axis in the font.

     Text {
         text: "Foobar"
         font.family: "MyVariableFont"
         font.variableAxes: { "wght": (Font.Normal + Font.Bold) / 2.0 }
     }

If the "wght" axis is supported by the font and the given value is within its defined range, a font corresponding to the weight 550.0 will be provided.

There are a few standard axes than many fonts provide, such as "wght" (weight), "wdth" (width), "ital" (italic) and "opsz" (optical size). They each have indivdual ranges defined in the font itself. For instance, "wght" may span from 100 to 900 (QFont::Thin to QFont::Black) whereas "ital" can span from 0 to 1 (from not italic to fully italic).

A font may also choose to define custom axes; the only limitation is that the name has to meet the requirements for a QFont::Tag (sequence of four latin-1 characters.)

By default, no variable axes are set.

Note: In order to use variable axes on Windows, the application has to run with either the FreeType or DirectWrite font databases. See the documentation for QGuiApplication::QGuiApplication() for more information on how to select these technologies.

This property was introduced in Qt 6.7.

See also QFont::setVariableAxis().

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.