Text, fonts and rich text
Display single-line or wrapped text, configure fonts, elide or
shrink overflowing lines, and render styled text, HTML, Markdown
and links with Text and FontLoader.
Use
Text to display plain strings, styled tags, rich HTML or Markdown, and use FontLoader when you need to load a custom font file by URL or path.A
Text item with no width set is as wide as its text (trailing spaces count towards the width), and updates its size whenever text changes. Once completion finishes, contentWidth, contentHeight, lineCount and truncated report how the text is laid out. Changing color, or changing alignment within a fixed width, does not measure the text again.To break long text into lines, set both a
width and a wrap (Text.NoWrap, Text.WordWrap, Text.WrapAnywhere, Text.Wrap):Without a
width, nothing wraps; without a wrap, the text stays on one line and overflows the item.WordWrap breaks between words so every line fits the width, though a single word wider than the item still overflows. WrapAnywhere breaks inside any word, and Wrap breaks inside a word only when there is no other break point.Each wrapped line adds one line height to the item's height, while
implicitWidth stays that of the unwrapped text. Explicit line breaks (\n) always start a new line even without a wrap mode, empty lines count, and contentWidth matches the widest line.To cut text that does not fit:
Set
maximumLineCount to drop lines past the limit and set truncated: true. The item's height is that of the kept lines. Explicit line breaks count towards the limit, and a limit that the text does not reach changes nothing.Set
elide (Text.ElideRight, Text.ElideLeft, Text.ElideMiddle, Text.ElideNone) along with a width to replace overflowing text with … so the result is no wider than the item. If not even … fits, nothing is shown and truncated becomes true.Combine
wrap, maximumLineCount and elide: Text.ElideRight to end the last allowed line with …. Lines that do not fit the item's height are dropped while implicitHeight remains that of all the lines; without an elide mode, a short item overflows instead of being cut.The first
Text wraps onto multiple lines; the second keeps two lines and ends the second with …; the third stays on one line and cuts the middle with ….Instead of eliding, set
fontSizeMode (Text.FixedSize by default, Text.HorizontalFit, Text.VerticalFit, Text.Fit) to draw the text at the largest size—up to the font's own size—that fits inside the item's width (on one line), height, or both. Text that already fits keeps its font size, and fitted text never shrinks below minimumPixelSize (or minimumPointSize when the font is sized in points; both default to 12).Watch the difference between text formats when fitting:
StyledText shrinks just like plain text, whereas Text.RichText ignores fontSizeMode and keeps its 40-pixel size.When you do not set a font,
Text uses the application font: family Sans Serif, size: 12 and weight: 400 (Font.Normal). You can configure font.family, font.size (in logical pixels), font.weight (Font.Thin, ExtraLight, Light, Normal, Medium, DemiBold, Bold, ExtraBold, Black), font.italic, font.underline, font.strikeout, font.letterSpacing, font.wordSpacing, font.capitalization and font.hintingPreference, as well as style (Text.Normal, Outline, Raised, Sunken), styleColor and renderType (Text.QtRendering, NativeRendering, CurveRendering).A size in points is written
font.size: Screen.points(n): Screen.points gives the pixels for n points on the item's screen, at the screen's logical dots per inch over 72, so 12 points are 16 pixels on a screen of 96 to the inch. font.size is a whole number of pixels, so a size that falls between two is rounded.Bold text (
font.weight: Font.Bold, 700) and positive letterSpacing or wordSpacing widen the text, whereas underline and strikeout do not change its size.If a font family is not installed on the machine, the system's font matching substitutes an existing family and measures with that face. Generic family names such as
serif or monospace resolve to the face the system names for them.FontLoader loads a font file from source, reporting status as FontLoader.Null (0), Ready (1), Loading (2) or Error (3). Once ready, name holds the family name that Text can reference. A missing or invalid font file enters Error and logs Cannot load font.To adjust vertical rhythm and placement:
lineHeight with lineHeightMode: Text.ProportionalHeight multiplies every line's height, or sets each line to an exact pixel height with Text.FixedHeight (an empty Text with a fixed line height still has one line of that height, and the last line is never shorter than its font).padding (leftPadding, topPadding, rightPadding, bottomPadding) surrounds the text; setting a side padding overrides padding on that side.align (Text.AlignLeft, AlignRight, AlignHCenter, AlignJustify) defaults to the natural direction of the first letter with a direction ( recoverable via effectiveHorizontalAlignment), and keeps any explicit alignment you set. verticalAlignment (Text.AlignTop, AlignVCenter, AlignBottom) defaults to AlignTop.format selects how text is parsed:Text.AutoText (2, the default): inspects the first line only. If the first line starts with a known tag, the text is read as StyledText; otherwise (including a bare <, an unknown tag or Markdown syntax) it is read as PlainText.Text.PlainText (0): displays all characters and tags literally.Text.StyledText (4): supports a small tag set—bold, italic, headings, font sizes, line breaks, paragraphs and list items. Unknown tags are stripped while keeping their text content, and an unclosed tag styles the rest of the text.Text.RichText (1): lays out an HTML subset as blocks with margins (paragraphs, headings, lists, quotes, tables and horizontal rules). Scripts and style sheets are ignored, unknown elements are dropped while keeping their content, and an unclosed paragraph ends where the next starts. Rich text always reports lineCount: 1 regardless of how many visual lines it spans, and wrapped rich text is as wide as its item.Text.MarkdownText (3): renders Markdown with bold, headings, lists, quotes, fenced code, tables and paragraphs separated by margins.Links written in
StyledText, RichText or MarkdownText are drawn in blue unless you set linkColor (in RichText, links take the palette's link colour rather than linkColor, though an inline style on the <a> tag itself overrides the palette).Pressing and releasing on a link emits
linkActivated(link) with the address as written; dragging off the link before release does not activate it, and pressing beside a link passes through to whatever lies beneath. Moving the pointer over a link updates hoveredLink and emits linkHovered(link) (emitting an empty string when the pointer leaves), and linkAt(x, y) returns the link address at a point or "". When a Text is in the Tab order, pressing Tab visits each link in reading order and Space or Return activates the focused link.Links in
RichText take the palette's colour instead of linkColor unless styled on the link element itself.A
MarkdownText document does not parse embedded HTML; HTML tags inside Markdown are shown as literal text.The margin between blocks in
MarkdownText is always 7 pixels, however many times text is set.An inline image in
RichText that fits within its line leaves the line height unchanged, and a relative baseUrl resolves beside the QML file.






