Text QML Type

Specifies how to add text to a scene. More...

Import Statement: import QtQuick .
Since: Qt Quick Ultralite 1.0


Inherited By:



Detailed Description

Text items can display plain text. For example, red text with a specific font and size can be defined like this:

Text {
    text: "Hello World!"
    font.family: "Helvetica"
    font.pointSize: 24
    color: "red"

If height and width are not explicitly set, Text will attempt to determine how much room is needed and set it accordingly. It will always prefer width to height (all text will be placed on a single line).

The Text element supports dynamically changing the text property. Prefer StaticText for cases where the displayed text fixed and known at compile-time.

See also Text Rendering and Fonts, Text QML Type, StaticText, Managing Resources and Assets, and Internationalization and Localization with Qt Quick Ultralite.

Property Documentation

bottomPadding : real

leftPadding : real

padding : real

rightPadding : real

topPadding : real

These properties hold the padding around the text.

This QML property was introduced in Qt Quick Ultralite 1.1.

horizontalAlignment : enumeration

verticalAlignment : enumeration

Sets the horizontal and vertical alignment of the text within the Text items width and height. By default, the text is vertically aligned to the top and horizontally aligned to the left.

The valid values for horizontalAlignment are Text.AlignLeft, Text.AlignRight, and Text.AlignHCenter. The valid values for verticalAlignment are Text.AlignTop, Text.AlignBottom, and Text.AlignVCenter.

Note that for a single line of text, the size of the text is the area of the text. In this common case, all alignments are equivalent. If you want the text to be, say, centered in its parent, then you will need to either modify the Item::anchors, or set horizontalAlignment to Text.AlignHCenter and bind the width to that of the parent.

baselineOffset : int

Specifies the position of the item's baseline in local coordinates.

The baseline is the imaginary line on which the text sits.

color : color

The text color.

An example of green text defined using hexadecimal notation:

Text {
    color: "#00FF00"
    text: "green text"

An example of steel blue text defined using an SVG color name:

Text {
    color: "steelblue"
    text: "blue text"

font.bold : bool

Sets whether the font weight is bold.

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.

The default font family is set via the QUL_DEFAULT_FONT_FAMILY CMake variable.

The glyphs for the selected fonts are compiled by the qulfontcompiler. It searches for fonts in the QUL_FONTS_DIR.

See also Text Rendering and Fonts.

font.italic : bool

Sets whether the font has an italic style.

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.unicodeCoverage : list

Adds to the list of unicode glyphs that are compiled into the binary for this font configuration.

The list may contain:

  • string literals containing glyphs to add, like "\u1722"
  • unicode block enum values, like Font.UnicodeBlock_Kannada
  • two-element lists denoting a unicode range, like [0x600, 0x61F]


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

Note: Glyphs that are contained in string literals in QML files do not need to be explicitly listed. The qmltocpp compiler collects these and the qulfontcompiler emits them for all font configurations automatically.

This property was introduced in Qt Quick Ultralite 1.1.

See also Text Rendering and Fonts.

font.weight : int

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

  • Font.Thin
  • Font.Light
  • Font.ExtraLight
  • Font.Normal - the default
  • Font.Medium
  • Font.DemiBold
  • Font.Bold
  • Font.ExtraBold
  • Font.Black
Text { text: "Hello"; font.weight: Font.DemiBold }

text : string

The text to display. Text supports plain text strings.

transform : list<Transform>

This property holds the list of transformations to apply.

For more information see Transform.

Available under certain Qt licenses.
Find out more.