class QSGTextNode#

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

Inheritance diagram of PySide6.QtQuick.QSGTextNode

New in version 6.7.

Synopsis#

Virtual methods#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

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

class TextStyle#

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

Constant

Description

QSGTextNode.Normal

The text is drawn without any style applied.

QSGTextNode.Outline

The text is drawn with an outline.

QSGTextNode.Raised

The text is drawn raised.

QSGTextNode.Sunken

The text is drawn sunken.

class RenderType#

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

Constant

Description

QSGTextNode.QtRendering

Text is rendered using a scalable distance field for each glyph.

QSGTextNode.NativeRendering

Text is rendered using a platform-specific technique.

QSGTextNode.CurveRendering

Text is rendered using a curve rasterizer running directly on the graphics hardware.

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.

Both Text.QtRendering and Text.CurveRendering are hardware-accelerated techniques. QtRendering is the faster of the two, but uses more memory and will exhibit rendering artifacts at large sizes. CurveRendering should be considered as an alternative in cases where QtRendering does not give good visual results or where reducing graphics memory consumption is a priority.

abstract addTextDocument(position, document[, selectionStart=-1[, selectionCount=-1]])#
Parameters:

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() .

See also

clear()

abstract addTextLayout(position, layout[, selectionStart=-1[, selectionCount=-1[, lineStart=0[, lineCount=-1]]]])#
Parameters:
  • positionQPointF

  • layoutQTextLayout

  • selectionStart – int

  • selectionCount – int

  • lineStart – int

  • lineCount – int

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.

See also

clear()

abstract clear()#

Clears the contents of the node, deleting nodes and other data that represents the layouts and documents that have been added to it.

abstract color()#
Return type:

QColor

Returns the main color used when rendering the text.

See also

setColor()

abstract filtering()#
Return type:

Filtering

Returns the sampling mode used when scaling images that are part of the displayed text.

See also

setFiltering()

abstract linkColor()#
Return type:

QColor

Returns the color of hyperlinks in the text.

See also

setLinkColor()

abstract renderType()#
Return type:

RenderType

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

See also

setRenderType()

abstract renderTypeQuality()#
Return type:

int

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

abstract selectionColor()#
Return type:

QColor

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

abstract selectionTextColor()#
Return type:

QColor

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

abstract setColor(color)#
Parameters:

colorQColor

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

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

See also

color()

abstract setFiltering(arg__1)#
Parameters:

arg__1Filtering

Sets the sampling mode used when scaling images that are part of the displayed text to filtering. For smoothly scaled images, use Linear here.

The default is Nearest .

See also

filtering()

abstract setLinkColor(linkColor)#
Parameters:

linkColorQColor

Sets the color of or hyperlinks to linkColor in the text.

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

See also

linkColor()

abstract setRenderType(renderType)#
Parameters:

renderTypeRenderType

Sets the type of glyph node in use to renderType.

The default is QtRendering .

See also

renderType()

abstract setRenderTypeQuality(renderTypeQuality)#
Parameters:

renderTypeQuality – int

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:

  • DefaultRenderTypeQuality

  • -1 (default)

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.

abstract setSelectionColor(selectionColor)#
Parameters:

selectionColorQColor

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()

abstract setSelectionTextColor(selectionTextColor)#
Parameters:

selectionTextColorQColor

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).

abstract setStyleColor(styleColor)#
Parameters:

styleColorQColor

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

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

abstract setTextStyle(textStyle)#
Parameters:

textStyleTextStyle

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

abstract setViewport(viewport)#
Parameters:

viewportQRectF

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()

abstract styleColor()#
Return type:

QColor

Returns the style color used when rendering the text.

abstract textStyle()#
Return type:

TextStyle

Returns the style of the rendered text.

abstract viewport()#
Return type:

QRectF

Returns the current viewport set for this QSGTextNode .

See also

setViewport()