このページでは

QSGTextNode Class

QSGTextNode クラスは、Qt Quick のシーングラフ内でテキストレイアウトやテキストドキュメントを描画するためのクラスです。詳細...

ヘッダー: #include <QSGTextNode>
CMake: find_package(Qt6 REQUIRED COMPONENTS Quick)
target_link_libraries(mytarget PRIVATE Qt6::Quick)
qmake: QT += quick
以下のように: 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

プライベート関数

virtual void doAddTextDocument(QPointF position, QTextDocument *document, int selectionStart, int selectionCount) = 0
virtual void doAddTextLayout(QPointF position, QTextLayout *layout, int selectionStart, int selectionCount, int lineStart, int lineCount) = 0

詳細な説明

QSGTextNodeは、テキストを必要とするカスタムQt Quick アイテムを作成する際に役立ちます。これは、Qt Quick において、Text、TextEdit 、およびTextInput 要素で使用されます。

QQuickWindow::createTextNode() を使用して QSGTextNode オブジェクトを作成できます。addTextLayout() およびaddTextDocument() 関数を使用すると、QSGTextNode にテキストを追加できます。テキストはあらかじめレイアウト済みである必要があります。

注:プロパティが 有効になるためには、addTextLayout() またはaddTextDocument() を呼び出す前に、プロパティを設定しておく必要があります。

注: QSGTextNodeの破棄は 慎重に管理する必要があります。特に、グラフィックリソースを参照しているため、Qt Quick のシーングラフが無効化される際に削除する必要があります。ノードがシーングラフの一部であり、OwnedByParent フラグが設定されている場合(これがデフォルトです)、これは自動的に行われます。 ただし、OwnedByParent フラグがクリアされており、ノードが手動で破棄される場合は、シーングラフが無効化された時点でこれを行うよう注意する必要があります。これは、QQuickWindow::sceneGraphInvalidated()シグナルに接続するか、QQuickItem サブクラス内でinvalidateSceneGraph() という名前のスロットを実装することで実現できます。詳細については、QQuickItem のドキュメントも参照してください。

メンバ型のドキュメント

enum QSGTextNode::RenderType

この列挙型は、テキストのレンダリングに使用されるグリフノードのタイプを表します。

定数値説明
QSGTextNode::QtRendering0テキストは、各グリフに対してスケーラブルな距離フィールドを使用してレンダリングされます。
QSGTextNode::NativeRendering1テキストは、プラットフォーム固有の手法を使用してレンダリングされます。
QSGTextNode::CurveRendering2テキストは、グラフィックスハードウェア上で直接実行されるカーブラスタライザを使用してレンダリングされます。

ターゲットプラットフォーム上でテキストをネイティブのように表示させたい場合、かつテキストの変形などの高度な機能を必要としない場合は、NativeRendering を選択してください。NativeRendering レンダリングタイプとこれらの機能を組み合わせて使用すると、画質が低下し、場合によってはピクセル化された結果になることがあります。

Text.QtRendering とText.CurveRendering はどちらもハードウェアアクセラレーション技術です。QtRendering は 2 つのうち高速ですが、より多くのメモリを使用し、大きなサイズではレンダリングアーティファクトが発生します。QtRendering で良好な視覚的結果が得られない場合や、グラフィックメモリの消費を抑えることが優先される場合は、CurveRendering を代替手段として検討してください。

setRenderType() およびsetRenderTypeQuality()も参照してください 。

enum QSGTextNode::TextStyle

この列挙型は、テキストの描画に適用できるスタイルを表します。

定数値説明
QSGTextNode::Normal0スタイルを一切適用せずにテキストが描画されます。
QSGTextNode::Outline1テキストはアウトライン付きで描画されます。
QSGTextNode::Raised2テキストは盛り上げられて描画されます。
QSGTextNode::Sunken3テキストは凹んで描画されます。

関連項目: setTextStyle() およびsetStyleColor()。

メンバ関数のドキュメント

void QSGTextNode::addTextDocument(QPointF position, QTextDocument *document, int selectionStart = -1, int selectionCount = -1)

document の内容を、position にあるテキストノードに追加します。selectionStart が 0 以上の場合、これはselectionCount 文字分の選択範囲の最初の文字をマークします。選択範囲はselectionColor() による背景塗りつぶしとして表現され、選択されたテキストはselectionTextColor() で描画されます。

この関数は、その引数を仮想関数doAddTextDocument()に転送します。

clear()も参照してください 。

void QSGTextNode::addTextLayout(QPointF position, QTextLayout *layout, int selectionStart = -1, int selectionCount = -1, int lineStart = 0, int lineCount = -1)

layout の内容を、position にあるテキストノードに追加します。selectionStart が 0 以上の場合、これはselectionCount 文字分の選択範囲の最初の文字としてマークされます。選択範囲はselectionColor() による背景塗りつぶしとして表現され、選択されたテキストはselectionTextColor() でレンダリングされます。

便宜上、lineStart およびlineCount を使用して、レイアウトから含めるQTextLine オブジェクトの範囲を選択できます。これは、例えば、省略レイアウトを作成する際に役立ちます。lineCount が< 0の場合、ノードにはlineStart からレイアウトの終わりまでの行が含まれます。

この関数は、その引数を仮想関数 `doAddTextLayout()` に転送します。

clear()も参照してください 。

[pure virtual] void QSGTextNode::clear()

ノードの内容を消去し、そのノードに追加されていたレイアウトやドキュメントを表すノードやその他のデータを削除します。

addTextLayout() およびaddTextDocument()も参照してください 。

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

テキストの描画に使用されるメインカラーを返します。

setColor()も参照してください 。

[pure virtual private] void QSGTextNode::doAddTextDocument(QPointF position, QTextDocument *document, int selectionStart, int selectionCount)

addTextDocument() によって呼び出される仮想関数。これは、document の内容をシーングラフノードに変換し、position にある現在のノードにそれらを追加します。

selectionStart が0以上の場合、これはselectionCount で指定された文字数の選択範囲の先頭文字を示します。選択範囲はselectionColor()による背景塗りつぶしとして表現され、選択されたテキストはselectionTextColor()で描画されます。

clear() およびaddTextDocument()も参照してください 。

[pure virtual private] void QSGTextNode::doAddTextLayout(QPointF position, QTextLayout *layout, int selectionStart, int selectionCount, int lineStart, int lineCount)

addTextLayout() によって呼び出される仮想関数。これは、layout の内容をシーングラフノードに変換し、それらをposition の現在のノードに追加します。

selectionStart が0以上の場合、これはselectionCount の文字数に相当する選択領域の最初の文字を示します。選択範囲はselectionColor()による背景塗りつぶしとして表現され、選択されたテキストはselectionTextColor()でレンダリングされます。

便宜上、lineStart およびlineCount を使用して、レイアウトから含めるQTextLine オブジェクトの範囲を選択できます。これは、例えば、省略されたレイアウトを作成する際に役立ちます。lineCount が< 0の場合、ノードにはlineStart からレイアウトの終わりまでの行が含まれます。

clear() およびaddTextLayout()も参照してください 。

[pure virtual] QSGTexture::Filtering QSGTextNode::filtering() const

表示されているテキストに含まれる画像を拡大・縮小する際に使用されるサンプリングモードを返します。

setFiltering()も参照してください 。

[pure virtual] QColor QSGTextNode::linkColor() const

テキスト内のハイパーリンクの色を返します。

setLinkColor()も参照してください 。

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

テキストのレンダリングに使用されるグリフノードの型を返します。

setRenderType()も参照してください 。

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

ノードのレンダリング品質を返します。詳細については、setRenderTypeQuality() を参照してください。

setRenderTypeQuality()も参照してください 。

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

テキストの任意の部分が選択状態になると、選択範囲の背景色を返します。

setSelectionColor()も参照してください 。

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

テキストの一部が選択状態になっている場合、その選択されたテキストの色を返します。

setSelectionTextColor()も参照してください 。

[pure virtual] void QSGTextNode::setColor(QColor color)

color にテキストを描画する際に使用するメインカラーを設定します。

デフォルトは黒です:QColor(0, 0, 0) 。

color()も参照してください 。

[pure virtual] void QSGTextNode::setFiltering(QSGTexture::Filtering filtering)

表示されているテキストに含まれる画像を拡大・縮小する際に使用するサンプリングモードを「filtering 」に設定します。画像を滑らかに拡大・縮小するには、ここで「QSGTexture::Linear 」を使用してください。

デフォルトは `QSGTexture::Nearest` です。

filtering()も参照してください 。

[pure virtual] void QSGTextNode::setLinkColor(QColor linkColor)

テキスト内のlinkColor へのハイパーリンクの色を設定します。

デフォルトは青色です:QColor(0, 0, 255) 。

linkColor()も参照してください 。

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

使用中のグリフノードのタイプを「renderType 」に設定します。

デフォルトは `QtRendering` です。

renderType()も参照してください 。

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

使用中のrenderType()がこれをサポートしている場合は、テキストのレンダリングに使用する品質を設定します。サポートされている場合、これを利用して、視覚的な忠実度と実行速度やメモリ使用量のバランスを調整することができます。

renderTypeQuality が< 0の場合、デフォルトの品質が使用されます。

renderTypeQuality には任意の整数を指定できますが、極端な値を設定すると、基盤となるグラフィックスハードウェアによる制限が生じる場合があります。Qt Quick の Text 要素では、以下の事前定義された値が使用されます:

定数説明
DefaultRenderTypeQuality-1(デフォルト)
LowRenderTypeQuality26
NormalRenderTypeQuality52
HighRenderTypeQuality104
VeryHighRenderTypeQuality208

この値は現在、QtRendering レンダリングタイプでのみ適用されます。この値を設定すると、グリフの表現に使用される距離フィールドの解像度が変更されます。標準値より高く設定すると、メモリ消費量は増加しますが、非常に大きなテキストにおけるフィルタリングによるアーティファクトが軽減されます。

デフォルト値は -1 です。

renderTypeQuality()も参照してください 。

[pure virtual] void QSGTextNode::setSelectionColor(QColor color)

テキストの任意の部分が選択状態になると、選択範囲の背景色をcolor に設定します。

デフォルトは濃い青(QColor(0, 0, 128) )です。

selectionColor()も参照してください 。

[pure virtual] void QSGTextNode::setSelectionTextColor(QColor selectionTextColor)

テキストの一部が選択状態になると、選択テキストの色をselectionTextColor に設定します。

デフォルトは白です:QColor(255, 255, 255) 。

selectionTextColor()も参照してください 。

[pure virtual] void QSGTextNode::setStyleColor(QColor styleColor)

styleColor にテキストを描画する際に使用するスタイルの色を設定します。

デフォルトは黒です:QColor(0, 0, 0) 。

styleColor() およびsetTextStyle()も参照してください 。

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

レンダリングされるテキストのスタイルを `textStyle` に設定します。デフォルトは `Normal` です。

textStyle() およびsetStyleColor()も参照してください 。

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

テキストが表示されるビューポートのバウンディング矩形を `viewport` に設定します。この情報を指定することで、QSGTextNode は、テキストレイアウトやドキュメントのどの部分をシーングラフに含めるかを最適化できるようになります。

デフォルトは、デフォルトのコンストラクタで生成された `QRectF` です。このビューポートの場合、すべてのコンテンツがシーングラフに含まれます。

viewport()も参照してください 。

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

テキストの描画に使用されるスタイルの色を返します。

setStyleColor() およびtextStyle()も参照してください 。

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

レンダリングされたテキストのスタイルを返します。

setTextStyle() およびstyleColor()も参照してください 。

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

このQSGTextNode に対して現在設定されているビューポートを返します。

setViewport()も参照してください 。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.