- Qt 6.11
- Qt Quick
- QML Types
- font
- Qt 6.11.2 Reference Documentation

# font QML Value Type

a font value with the properties of QFont. The `font` type refers to a font value with the properties of QFont. More...

## Properties

- bold : bool
- capitalization : enumeration
- contextFontMerging : bool `(since 6.8)`
- family : string
- features : object `(since 6.6)`
- hintingPreference : enumeration
- italic : bool
- kerning : bool
- letterSpacing : real
- pixelSize : int
- pointSize : real
- preferShaping : bool
- preferTypoLineMetrics : bool `(since 6.8)`
- strikeout : bool
- styleName : string
- underline : bool
- variableAxes : object `(since 6.7)`
- weight : int
- wordSpacing : real

## Detailed Description

Properties of type `font` default to the application's default font.

Example:

         Text {
             font.family: "Helvetica"
             font.pointSize: 13
             font.bold: true
         }

As `font` is a structured value type, it can also be constructed with a JavaScript object:

         readonly property font myFont: ({
             family: "Helvetica",
             pointSize: 13,
             bold: true
         })

When integrating with C++, note that any QFont value passed into QML from C++ is automatically converted into a `font` value, and vice-versa.

This value type is provided by the QtQuick import.

See also QML Value Types.

## Property Documentation

### bold : bool

Whether the font weight is bold.

### capitalization : enumeration

The capitalization for a text.

Constant | Description
--- | ---
`Font.MixedCase` | the normal case: 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
     Text { text: "Hello"; font.capitalization: Font.AllLowercase }

### contextFontMerging : bool `[since 6.8]`

If the selected font does not contain a certain character, Qt automatically chooses a similar-looking fallback font that contains the character. By default this is done on a character-by-character basis.

This means that in certain uncommon cases, many different fonts may be used to represent one string of text even if it's in the same script. Setting `contextFontMerging` to true will try finding the fallback font that matches the largest subset of the input string instead. This will be more expensive for strings where missing glyphs occur, but may give more consistent results. By default, `contextFontMerging` is `false`.

This property was introduced in Qt 6.8.

See also QFont::StyleStrategy.

### family : string

The family name of the font.

The family name is case insensitive and may optionally include a foundry name, for example "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.

### features : object `[since 6.6]`

Applies integer values to specific OpenType features when shaping the text based on the contents. 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. 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().

### hintingPreference : enumeration

The preferred hinting on the text.

This is a hint to the underlying text rendering system to use a certain level of hinting, and has varying support across platforms. See the table in the documentation for QFont::HintingPreference for more details.

Note: This property only has an effect when used together with render type Text.NativeRendering.

Constant | Description
--- | ---
`Font.PreferDefaultHinting` | Use the default hinting level for the target platform.
`Font.PreferNoHinting` | If possible, render text without hinting the outlines of the glyphs. The text layout will be typographically accurate, using the same metrics as are used, for example, when printing.
`Font.PreferVerticalHinting` | If possible, render text with no horizontal hinting, but align glyphs to the pixel grid in the vertical direction. The text will appear crisper on displays where the density is too low to give an accurate rendering of the glyphs. But since the horizontal metrics of the glyphs are unhinted, the text's layout will be scalable to higher density devices (such as printers) without impacting details such as line breaks.
`Font.PreferFullHinting` | If possible, render text with hinting in both horizontal and vertical directions. The text will be altered to optimize legibility on the target device, but since the metrics will depend on the target size of the text, the positions of glyphs, line breaks, and other typographical detail will not scale, meaning that a text layout may look different on devices with different pixel densities.
     Text { text: "Hello"; renderType: Text.NativeRendering; font.hintingPreference: Font.PreferVerticalHinting }

### italic : bool

Whether the font has an italic style.

### 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`.

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

### letterSpacing : real

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.

### pixelSize : int

The font size in pixels.

Makes the font device dependent. Use `pointSize` to set the size of the font in a device independent manner.

### pointSize : real

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

### 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 for example 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`.

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

### preferTypoLineMetrics : bool `[since 6.8]`

competing sets of the vertical line metrics that provide the ascent, descent and leading of the font. These are often referred to as the win (Windows) metrics and the typo (typographical) metrics. While the specification recommends using the `typo` metrics for line spacing, many applications prefer the `win` metrics unless the `USE_TYPO_METRICS` flag is set in the fsSelection field of the font. For backwards-compatibility reasons, this is also the case for Qt applications. This is not an issue for fonts that set the `USE_TYPO_METRICS` flag to indicate that the `typo` metrics are valid, nor for fonts where the `win` metrics and `typo` metrics match up. However, for certain fonts the `win` metrics may be larger than the preferable line spacing and the `USE_TYPO_METRICS` flag may be unset by mistake. For such fonts, setting `font.preferTypoLineMetrics` may give superior results.

By default, `preferTypoLineMetrics` is `false`.

This property was introduced in Qt 6.8.

See also QFont::StyleStrategy.

### strikeout : bool

Whether the font has a strikeout style.

### styleName : string

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.

### underline : bool

Whether the text is underlined.

### 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 individual 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: On Windows, variable axes are not supported if the optional GDI font backend is in use.

This property was introduced in Qt 6.7.

See also QFont::setVariableAxis().

### weight : int

The requested weight of the font. The weight requested must be an integer between 1 and 1000, or one of the predefined values:

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
     Text { text: "Hello"; font.weight: Font.DemiBold }

### wordSpacing : real

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.