QSGTextNode Class | Qt Quick 6.7.0
Description: The QSGTextNode class is a class for drawing text layouts and text documents in the Qt Quick scene graph.

- Qt 6.7
- Qt Quick
- C++ Classes
- QSGTextNode
- Qt 6.7.0 Reference Documentation

# QSGTextNode Class

The QSGTextNode class is a class for drawing text layouts and text documents in the Qt Quick scene graph. More...

Header: | #include <QSGTextNode>
CMake: | find_package(Qt6 REQUIRED COMPONENTS Quick) target_link_libraries(mytarget PRIVATE Qt6::Quick)
qmake: | QT += quick
Since: | Qt 6.7
Inherits: | QSGTransformNode

- List of all members, including inherited members

## Public Types

enum | RenderType { QtRendering, NativeRendering }
enum | TextStyle { Normal, Outline, Raised, Sunken }

## Public Functions

virtual void | addTextDocument(const QPointF &position, QTextDocument *document, int selectionStart = -1, int selectionCount = -1) = 0
virtual void | addTextLayout(const QPointF &position, QTextLayout *layout, int selectionStart = -1, int selectionCount = -1, int lineStart = 0, int lineCount = -1) = 0
virtual QColor | anchorColor() const = 0
virtual QColor | color() const = 0
virtual QSGTextNode::RenderType | renderType() const = 0
virtual int | renderTypeQuality() const = 0
virtual QColor | selectionColor() const = 0
virtual QColor | selectionTextColor() const = 0
virtual void | setAnchorColor(const QColor &anchorColor) = 0
virtual void | setColor(const QColor &color) = 0
virtual void | setRenderType(QSGTextNode::RenderType renderType) = 0
virtual void | setRenderTypeQuality(int renderTypeQuality) = 0
virtual void | setSelectionColor(const QColor &color) = 0
virtual void | setSelectionTextColor(const QColor &selectionTextColor) = 0
virtual void | setSmooth(bool smooth) = 0
virtual void | setStyleColor(const QColor &styleColor) = 0
virtual void | setTextStyle(QSGTextNode::TextStyle textStyle) = 0
virtual void | setViewport(const QRectF &viewport) = 0
virtual bool | smooth() const = 0
virtual QColor | styleColor() const = 0
virtual QSGTextNode::TextStyle | textStyle() = 0
virtual QRectF | viewport() const = 0

## Detailed Description

QSGTextNode can be useful for creating custom Qt Quick items that require text. It is used in Qt Quick by the Text, TextEdit and TextInput elements.

You can create QSGTextNode objects using QQuickWindow::createTextNode(). The addTextLayout() and addTextDocument() functions provide ways to add text to the QSGTextNode. The text must already be laid out.

Note: Properties must be set before addTextLayout() or addTextDocument() are called in order to have an effect.

## Member Type Documentation

### enum QSGTextNode::RenderType

This enum type describes type of glyph node used for rendering the text.

Constant | Value | Description
--- | --- | ---
`QSGTextNode::QtRendering` | `0` | Text is rendered using a scalable distance field for each glyph.
`QSGTextNode::NativeRendering` | `1` | Text is rendered using a platform-specific technique.

Select `NativeRendering` if you prefer text to look native on the target platform and do not require advanced features such as transformation of the text. Using such features in combination with the NativeRendering render type will lend poor and sometimes pixelated results.

See also setRenderType() and setRenderTypeQuality().

### enum QSGTextNode::TextStyle

This enum type describes styles that can be applied to text rendering.

Constant | Value | Description
--- | --- | ---
`QSGTextNode::Normal` | `0` | The text is drawn without any style applied.
`QSGTextNode::Outline` | `1` | The text is drawn with an outline.
`QSGTextNode::Raised` | `2` | The text is drawn raised.
`QSGTextNode::Sunken` | `3` | The text is drawn sunken.

See also setTextStyle() and setStyleColor().

## Member Function Documentation

### `[pure virtual]` void QSGTextNode::addTextDocument(const QPointF &position, QTextDocument *document, int selectionStart = -1, int selectionCount = -1)

Adds the contents of document to the text node at position. If selectionStart is >= 0, then this marks the first character in a selected area of selectionCount number of characters. The selection is represented as a background fill with the selectionColor() and the selected text is rendered in the selectionTextColor().

### `[pure virtual]` void QSGTextNode::addTextLayout(const QPointF &position, QTextLayout *layout, int selectionStart = -1, int selectionCount = -1, int lineStart = 0, int lineCount = -1)

Adds the contents of layout to the text node at position. If selectionStart is >= 0, then this marks the first character in a selected area of selectionCount number of characters. The selection is represented as a background fill with the selectionColor() and the selected text is rendered in the selectionTextColor().

For convenience, lineStart and lineCount can be used to select the range of QTextLine objects to include from the layout. This can be useful, for instance, when creating elided layouts. If lineCount is < 0, then the the node will include the lines from lineStart to the end of the layout.

### `[pure virtual]` QColor QSGTextNode::anchorColor() const

Returns the color of anchors (or hyperlinks) in the text.

See also setAnchorColor().

### `[pure virtual]` QColor QSGTextNode::color() const

Returns the main color used when rendering the text.

See also setColor().

### `[pure virtual]` QSGTextNode::RenderType QSGTextNode::renderType() const

Returns the type of glyph node used for rendering the text.

See also setRenderType().

### `[pure virtual]` int QSGTextNode::renderTypeQuality() const

Returns the render type quality of the node. See setRenderTypeQuality() for details.

See also setRenderTypeQuality().

### `[pure virtual]` QColor QSGTextNode::selectionColor() const

Returns the color of the selection background when any part of the text is marked as selected.

See also setSelectionColor().

### `[pure virtual]` QColor QSGTextNode::selectionTextColor() const

Returns the color of the selection text when any part of the text is marked as selected.

See also setSelectionTextColor().

### `[pure virtual]` void QSGTextNode::setAnchorColor(const QColor &anchorColor)

Sets the color of anchors (or hyperlinks) to anchorColor in the text.

The default is blue: `QColor(0, 0, 255)`.

See also anchorColor().

### `[pure virtual]` void QSGTextNode::setColor(const QColor &color)

Sets the main color to use when rendering the text to color.

The default is black: `QColor(0, 0, 0)`.

See also color().

### `[pure virtual]` void QSGTextNode::setRenderType(QSGTextNode::RenderType renderType)

Sets the type of glyph node in use to renderType.

The default is QtRendering.

See also renderType().

### `[pure virtual]` void QSGTextNode::setRenderTypeQuality(int renderTypeQuality)

If the renderType() in use supports it, set the quality to use when rendering the text. When supported, this can be used to trade visual fidelity for execution speed or memory.

When the renderTypeQuality is < 0, the default quality is used.

The renderTypeQuality can be any integer, although limitations imposed by the underlying graphics hardware may be encountered if extreme values are set. The Qt Quick Text element operates with the following predefined values:

Constant | Description
--- | ---
`DefaultRenderTypeQuality` | -1 (default)
`LowRenderTypeQuality` | 26
`NormalRenderTypeQuality` | 52
`HighRenderTypeQuality` | 104
`VeryHighRenderTypeQuality` | 208

This value is currently only respected by the QtRendering render type. Setting it changes the resolution of the distance fields used to represent the glyphs. Setting it above normal will cause memory consumption to increase, but reduces filtering artifacts on very large text.

The default is -1.

See also renderTypeQuality().

### `[pure virtual]` void QSGTextNode::setSelectionColor(const QColor &color)

Sets the color of the selection background to color when any part of the text is marked as selected.

The default is dark blue: `QColor(0, 0, 128)`.

See also selectionColor().

### `[pure virtual]` void QSGTextNode::setSelectionTextColor(const QColor &selectionTextColor)

Sets the color of the selection text to selectionTextColor when any part of the text is marked as selected.

The default is white: `QColor(255, 255, 255)`.

See also selectionTextColor().

### `[pure virtual]` void QSGTextNode::setSmooth(bool smooth)

Sets the smoothness of the text node to smooth. This should typically match the item's QQuickItem::smooth property.

The default is false.

See also smooth().

### `[pure virtual]` void QSGTextNode::setStyleColor(const QColor &styleColor)

Sets the style color to use when rendering the text to styleColor.

The default is black: `QColor(0, 0, 0)`.

See also styleColor() and setTextStyle().

### `[pure virtual]` void QSGTextNode::setTextStyle(QSGTextNode::TextStyle textStyle)

Sets the style of the rendered text to textStyle. The default is `Normal`.

See also textStyle() and setStyleColor().

### `[pure virtual]` void QSGTextNode::setViewport(const QRectF &viewport)

Sets the bounding rect of the viewport where the text is displayed to viewport. Providing this information makes it possible for the QSGTextNode to optimize which parts of the text layout or document are included in the scene graph.

The default is a default-constructed QRectF. For this viewport, all contents will be included in the graph.

See also viewport().

### `[pure virtual]` bool QSGTextNode::smooth() const

Returns whether the QSGTextNode will be rendered as smooth or not.

See also setSmooth().

### `[pure virtual]` QColor QSGTextNode::styleColor() const

Returns the style color used when rendering the text.

See also setStyleColor() and textStyle().

### `[pure virtual]` QSGTextNode::TextStyle QSGTextNode::textStyle()

Returns the style of the rendered text.

See also setTextStyle() and styleColor().

### `[pure virtual]` QRectF QSGTextNode::viewport() const

Returns the current viewport set for this QSGTextNode.

See also setViewport().