C

font QML Basic Type

A font type describing a font configuration. The available properties are:

When using the Monotype Spark font engine, the font configuration uses the font class mapping rules.

See also Text Rendering and Fonts, Qt.font(), and Basic Types for more information.

This basic type is provided by the QtQuick import.

Usage example

Text {
    font.family: "Helvetica";
    font.pixelSize: 24;
    font.bold: true
}

Constant font configurations

A constant font configuration is where all the font's subproperties can be resolved to a constant value by qmltocpp. Binding to a readonly property is therefore permitted. Example:

readonly property int titlePixelSize: 40

Text {
    text: "hello world"
    font.pixelSize: titlePixelSize
}

Note: The static font engine supports only constant font configurations.

Font family

Sets the family name of the font. The default font familiy is set by QUL_DEFAULT_FONT_FAMILY.

Static font engine

The family name is case insensitive and may 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 is set using the font matching algorithm.

Spark font engine

The value of QUL_DEFAULT_FONT_FAMILY CMake target property is read when using the Fontmap file format. Otherwise, only the font.pixelSize font configuration is used.

Font bold

Sets whether the font weight is bold.

Font italic

Sets whether the font has an italic style.

Font pointSize

The pointSize property does not respect screen DPI as documented on the known issues or limitations page. Currently the set value is simply scaled to 1.5 times. It is recommented to use font.pixelSize instead.

Font pixelSize

Sets the font size in pixels.

Font unicodeCoverage

This property is permitted only on constant font configurations. The font compiler needs to know full font information at compile time to pre-generate the glyph data.

The array may contain:

  • String literals containing glyphs to add, like "\u1722".
  • Unicode block enum values, like Font.UnicodeBlock_Kannada. For the list of supported enum values, see unicode block names.
  • A list of pairs indicating a unicode range, like [0x600, 0x61F].

Example:

Text {
    font.family: "DejaVu Sans"
    font.unicodeCoverage: [Font.UnicodeBlock_Kannada, "ᜠᜡ\u1722", [0x600, 0x61F]]
    text: CppSingleton.retrieveText()
}

In the earlier example, the glyphs for many extra unicode codepoints are prerendered for the font configuration used by the Text item. This information is compiled into the application binary. The codepoints in the "Kannada" Unicode block, the codepoint range 0x600 to 0x61F (inclusive), and the individual characters ᜠ, ᜡ, and U+1722 will be included.

Only a single glyph is generated per codepoint, even if the codepoint is contained in several ranges, blocks, or strings.

Note: The unicodeCoverage property has a different meaning, depending on the used font engine. See Text Rendering and Fonts for font engine-specific details.

Font weight

Sets the font's weight. The following enums are supported:

  • Font.Thin
  • Font.ExtraLight
  • Font.Light
  • Font.Normal
  • Font.Medium
  • Font.DemiBold
  • Font.Bold
  • Font.ExtraBold
  • Font.Black

Font quality

The rendering quality of a font.

The font.quality property allows more fine-grained optimization, by providing hints to render low-quality glyphs.

The requested quality must be one of the predefined values:

  • Font.QualityVeryLow
  • Font.QualityVeryHigh

Example:

Text {
    font: Qt.font({ quality: Font.QualityVeryHigh })
    text: "..."
}

Note: The quality property can be set only in the Qt.font() function.

Optimization

By default, the font compiler generates glyphs for all used characters in all used font configurations. This may result in redundant glyphs being generated. For example:

Text {
    font: Qt.font({ quality: Font.QualityVeryHigh })
    text: "a"
}
Text {
    font: Qt.font({ quality: Font.QualityVeryLow })
    text: "b"
}

In the earlier example, glyphs for the "ab" characters are generated twice, one for VeryHigh and the other for VeryLow quality. This allows binding text property between existing Text items. You can disable this behavior by setting the QUL_AUTO_GENERATE_GLYPHS to OFF.

To set the default font quality for an application, see the QUL_DEFAULT_FONT_QUALITY CMake variable.

Available under certain Qt licenses.
Find out more.