The QSGTextNode class is a class for drawing text layouts and text documents in the Qt Quick scene graph. 更多...
头: | #include <QSGTextNode> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Quick)
target_link_libraries(mytarget PRIVATE Qt6::Quick) |
qmake: | QT += quick |
Since: | Qt 6.7 |
继承: | QSGTransformNode |
enum | RenderType { QtRendering, NativeRendering, CurveRendering } |
enum | TextStyle { Normal, Outline, Raised, Sunken } |
void | addTextDocument (QPointF position , QTextDocument * document , int selectionStart = -1, int selectionCount = -1) |
void | addTextLayout (QPointF position , QTextLayout * layout , int selectionStart = -1, int selectionCount = -1, int lineStart = 0, int lineCount = -1) |
virtual void | clear () = 0 |
virtual QColor | color () const = 0 |
virtual QSGTexture::Filtering | filtering () const = 0 |
virtual QColor | linkColor () 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 | setColor (QColor color ) = 0 |
virtual void | setFiltering (QSGTexture::Filtering filtering ) = 0 |
virtual void | setLinkColor (QColor linkColor ) = 0 |
virtual void | setRenderType (QSGTextNode::RenderType renderType ) = 0 |
virtual void | setRenderTypeQuality (int renderTypeQuality ) = 0 |
virtual void | setSelectionColor (QColor color ) = 0 |
virtual void | setSelectionTextColor (QColor selectionTextColor ) = 0 |
virtual void | setStyleColor (QColor styleColor ) = 0 |
virtual void | setTextStyle (QSGTextNode::TextStyle textStyle ) = 0 |
virtual void | setViewport (const QRectF & viewport ) = 0 |
virtual QColor | styleColor () const = 0 |
virtual QSGTextNode::TextStyle | textStyle () = 0 |
virtual QRectF | viewport () const = 0 |
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 元素。
You can create QSGTextNode objects using QQuickWindow::createTextNode ()。 addTextLayout () 和 addTextDocument () functions provide ways to add text to the QSGTextNode. The text must already be laid out.
注意: Properties must be set before addTextLayout () 或 addTextDocument () are called in order to have an effect.
This enum type describes type of glyph node used for rendering the text.
常量 | 值 | 描述 |
---|---|---|
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. |
QSGTextNode::CurveRendering
|
2
|
Text is rendered using a curve rasterizer running directly on the graphics hardware. |
选择
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.
另请参阅 setRenderType () 和 setRenderTypeQuality ().
This enum type describes styles that can be applied to text rendering.
常量 | 值 | 描述 |
---|---|---|
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. |
另请参阅 setTextStyle () 和 setStyleColor ().
Adds the contents of document to the text node at position 。若 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 ().
This function forwards its arguments to the virtual function doAddTextDocument().
另请参阅 clear () and doAddTextDocument().
Adds the contents of layout to the text node at position 。若 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.
This function forwards its arguments to the virtual function doAddTextLayout().
另请参阅 clear () and doAddTextLayout().
[pure virtual]
void
QSGTextNode::
clear
()
Clears the contents of the node, deleting nodes and other data that represents the layouts and documents that have been added to it.
另请参阅 addTextLayout () 和 addTextDocument ().
[pure virtual]
QColor
QSGTextNode::
color
() const
Returns the main color used when rendering the text.
另请参阅 setColor ().
[pure virtual]
QSGTexture::Filtering
QSGTextNode::
filtering
() const
Returns the sampling mode used when scaling images that are part of the displayed text.
另请参阅 setFiltering ().
[pure virtual]
QColor
QSGTextNode::
linkColor
() const
Returns the color of hyperlinks in the text.
另请参阅 setLinkColor ().
[pure virtual]
QSGTextNode::RenderType
QSGTextNode::
renderType
() const
Returns the type of glyph node used for rendering the text.
另请参阅 setRenderType ().
[pure virtual]
int
QSGTextNode::
renderTypeQuality
() const
Returns the render type quality of the node. See setRenderTypeQuality () 了解细节。
另请参阅 setRenderTypeQuality ().
[pure virtual]
QColor
QSGTextNode::
selectionColor
() const
Returns the color of the selection background when any part of the text is marked as selected.
另请参阅 setSelectionColor ().
[pure virtual]
QColor
QSGTextNode::
selectionTextColor
() const
Returns the color of the selection text when any part of the text is marked as selected.
另请参阅 setSelectionTextColor ().
[pure virtual]
void
QSGTextNode::
setColor
(
QColor
color
)
Sets the main color to use when rendering the text to color .
The default is black:
QColor(0, 0, 0)
.
另请参阅 color ().
[pure virtual]
void
QSGTextNode::
setFiltering
(
QSGTexture::Filtering
filtering
)
Sets the sampling mode used when scaling images that are part of the displayed text to filtering . For smoothly scaled images, use QSGTexture::Linear 这里。
默认为 QSGTexture::Nearest .
另请参阅 filtering ().
[pure virtual]
void
QSGTextNode::
setLinkColor
(
QColor
linkColor
)
Sets the color of or hyperlinks to linkColor in the text.
The default is blue:
QColor(0, 0, 255)
.
另请参阅 linkColor ().
[pure virtual]
void
QSGTextNode::
setRenderType
(
QSGTextNode::RenderType
renderType
)
Sets the type of glyph node in use to renderType .
默认为 QtRendering .
另请参阅 renderType ().
[pure virtual]
void
QSGTextNode::
setRenderTypeQuality
(
int
renderTypeQuality
)
若 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.
当 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) |
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.
另请参阅 renderTypeQuality ().
[pure virtual]
void
QSGTextNode::
setSelectionColor
(
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)
.
另请参阅 selectionColor ().
[pure virtual]
void
QSGTextNode::
setSelectionTextColor
(
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)
.
另请参阅 selectionTextColor ().
[pure virtual]
void
QSGTextNode::
setStyleColor
(
QColor
styleColor
)
Sets the style color to use when rendering the text to styleColor .
The default is black:
QColor(0, 0, 0)
.
另请参阅 styleColor () 和 setTextStyle ().
[pure virtual]
void
QSGTextNode::
setTextStyle
(
QSGTextNode::TextStyle
textStyle
)
Sets the style of the rendered text to
textStyle
。默认为
Normal
.
另请参阅 textStyle () 和 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.
另请参阅 viewport ().
[pure virtual]
QColor
QSGTextNode::
styleColor
() const
Returns the style color used when rendering the text.
另请参阅 setStyleColor () 和 textStyle ().
[pure virtual]
QSGTextNode::TextStyle
QSGTextNode::
textStyle
()
Returns the style of the rendered text.
另请参阅 setTextStyle () 和 styleColor ().
[pure virtual]
QRectF
QSGTextNode::
viewport
() const
Returns the current viewport set for this QSGTextNode .
另请参阅 setViewport ().