PySide6.QtQuick.QSGTextNode¶
- class QSGTextNode¶
The
QSGTextNodeclass is a class for drawing text layouts and text documents in the Qt Quick scene graph. More…Added in version 6.7.
Synopsis¶
Methods¶
def
addTextLayout()
Virtual methods¶
def
clear()def
color()def
filtering()def
linkColor()def
renderType()def
selectionColor()def
setColor()def
setFiltering()def
setLinkColor()def
setRenderType()def
setStyleColor()def
setTextStyle()def
setViewport()def
styleColor()def
textStyle()def
viewport()
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¶
QSGTextNodecan 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
QSGTextNodeobjects usingcreateTextNode(). TheaddTextLayout()andaddTextDocument()functions provide ways to add text to theQSGTextNode. The text must already be laid out.Note
Properties must be set before
addTextLayout()oraddTextDocument()are called in order to have an effect.Note
The destruction of
QSGTextNodehas to be managed with care. In particular, since it references graphics resources, it must be deleted when the Qt Quick scene graph is invalidated. If the node is part of the graph and has theOwnedByParentflag set (which is the default), this will happen automatically. However, if theOwnedByParentflag is cleared and the node is disposed of manually, care must be taken to do this when the scene graph is invalidated. This can be done by connecting to thesceneGraphInvalidated()signal, or by implementing a slot in theQQuickItemsubclass which is namedinvalidateSceneGraph(). See also the documentation ofQQuickItemfor more details.- class TextStyle¶
This enum type describes styles that can be applied to text rendering.
Constant
Description
QSGTextNode.TextStyle.Normal
The text is drawn without any style applied.
QSGTextNode.TextStyle.Outline
The text is drawn with an outline.
QSGTextNode.TextStyle.Raised
The text is drawn raised.
QSGTextNode.TextStyle.Sunken
The text is drawn sunken.
See also
- class RenderType¶
This enum type describes type of glyph node used for rendering the text.
Constant
Description
QSGTextNode.RenderType.QtRendering
Text is rendered using a scalable distance field for each glyph.
QSGTextNode.RenderType.NativeRendering
Text is rendered using a platform-specific technique.
QSGTextNode.RenderType.CurveRendering
Text is rendered using a curve rasterizer running directly on the graphics hardware.
Select
NativeRenderingif 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.QtRenderingandText.CurveRenderingare hardware-accelerated techniques.QtRenderingis the faster of the two, but uses more memory and will exhibit rendering artifacts at large sizes.CurveRenderingshould be considered as an alternative in cases whereQtRenderingdoes not give good visual results or where reducing graphics memory consumption is a priority.See also
- addTextDocument(position, document[, selectionStart=-1[, selectionCount=-1]])¶
- Parameters:
position –
QPointFdocument –
QTextDocumentselectionStart – int
selectionCount – int
Adds the contents of
documentto the text node atposition. IfselectionStartis >= 0, then this marks the first character in a selected area ofselectionCountnumber of characters. The selection is represented as a background fill with theselectionColor()and the selected text is rendered in theselectionTextColor().This function forwards its arguments to the virtual function doAddTextDocument().
See also
clear()doAddTextDocument()- addTextLayout(position, layout[, selectionStart=-1[, selectionCount=-1[, lineStart=0[, lineCount=-1]]]])¶
- Parameters:
position –
QPointFlayout –
QTextLayoutselectionStart – int
selectionCount – int
lineStart – int
lineCount – int
Adds the contents of
layoutto the text node atposition. IfselectionStartis >= 0, then this marks the first character in a selected area ofselectionCountnumber of characters. The selection is represented as a background fill with theselectionColor()and the selected text is rendered in theselectionTextColor().For convenience,
lineStartandlineCountcan be used to select the range of QTextLine objects to include from the layout. This can be useful, for instance, when creating elided layouts. IflineCountis < 0, then the the node will include the lines fromlineStartto the end of the layout.This function forwards its arguments to the virtual function doAddTextLayout().
See also
clear()doAddTextLayout()- 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.
See also
Returns the main color used when rendering the text.
See also
Returns the sampling mode used when scaling images that are part of the displayed text.
See also
Returns the color of hyperlinks in the text.
See also
- abstract renderType()¶
- Return type:
Returns the type of glyph node used for rendering the text.
See also
- abstract renderTypeQuality()¶
- Return type:
int
Returns the render type quality of the node. See
setRenderTypeQuality()for details.See also
Returns the color of the selection background when any part of the text is marked as selected.
See also
Returns the color of the selection text when any part of the text is marked as selected.
See also
Sets the main color to use when rendering the text to
color.The default is black:
QColor(0, 0, 0).See also
Sets the sampling mode used when scaling images that are part of the displayed text to
filtering. For smoothly scaled images, useLinearhere.The default is
Nearest.See also
Sets the color of or hyperlinks to
linkColorin the text.The default is blue:
QColor(0, 0, 255).See also
- abstract setRenderType(renderType)¶
- Parameters:
renderType –
RenderType
Sets the type of glyph node in use to
renderType.The default is
QtRendering.See also
- 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
renderTypeQualityis < 0, the default quality is used.The
renderTypeQualitycan 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
QtRenderingrender 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
Sets the color of the selection background to
colorwhen any part of the text is marked as selected.The default is dark blue:
QColor(0, 0, 128).See also
Sets the color of the selection text to
selectionTextColorwhen any part of the text is marked as selected.The default is white:
QColor(255, 255, 255).See also
Sets the style color to use when rendering the text to
styleColor.The default is black:
QColor(0, 0, 0).See also
Sets the style of the rendered text to
textStyle. The default isNormal.See also
Sets the bounding rect of the viewport where the text is displayed to
viewport. Providing this information makes it possible for theQSGTextNodeto 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
Returns the style color used when rendering the text.
See also
Returns the style of the rendered text.
See also
Returns the current viewport set for this
QSGTextNode.See also