QTextDocumentFragment Class

QTextDocumentFragment クラスは、QTextDocument のフォーマットされたテキストの一部を表します

ヘッダー #include <QTextDocumentFragment>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui

注意:このクラスの関数はすべてリエントラントです。

パブリック関数

QTextDocumentFragment()
QTextDocumentFragment(const QTextCursor &cursor)
QTextDocumentFragment(const QTextDocument *document)
QTextDocumentFragment(const QTextDocumentFragment &other)
~QTextDocumentFragment()
bool isEmpty() const
QString toHtml() const
(since 6.4) QString toMarkdown(QTextDocument::MarkdownFeatures features = QTextDocument::MarkdownDialectGitHub) const
QString toPlainText() const
(since 6.4) QString toRawText() const
QTextDocumentFragment &operator=(const QTextDocumentFragment &other)

静的パブリックメンバ

QTextDocumentFragment fromHtml(const QString &text, const QTextDocument *resourceProvider = nullptr)
(since 6.4) QTextDocumentFragment fromMarkdown(const QString &markdown, QTextDocument::MarkdownFeatures features = QTextDocument::MarkdownDialectGitHub)
QTextDocumentFragment fromPlainText(const QString &plainText)

詳しい説明

QTextDocumentFragment は、QTextDocument に挿入できるリッチテキストの断片です。文書断片は、QTextDocument から作成したり、QTextCursor の選択範囲から作成したり、別の文書断片から作成したりすることができます。文書フ ラ グ メ ン ト は、 静的関数fromPlainText () ・fromHtml () で作成す る こ と も で き ます。

文書断片の内容は、toRawText() 関数で生テキストとして、toPlainText() 関数で ASCII として、toHtml() 関数で HTML として、toMarkdown() 関数で Markdown として取得することができます。

メンバ関数ドキュメント

QTextDocumentFragment::QTextDocumentFragment()

空の QTextDocumentFragment を作成します。

isEmpty()も参照してください

[explicit] QTextDocumentFragment::QTextDocumentFragment(const QTextCursor &cursor)

cursor の選択範囲から QTextDocumentFragment を作成します。カーソルに選択範囲がない場合、作成されるフラグメントは空です。

isEmpty() およびQTextCursor::selection()も参照してください

[explicit] QTextDocumentFragment::QTextDocumentFragment(const QTextDocument *document)

与えられたdocument を QTextDocumentFragment に変換します。QTextDocumentFragment はドキュメントの内容のみを保存し、ドキュメントのタイトルのようなメタ情報は保存しないことに注意してください。

QTextDocumentFragment::QTextDocumentFragment(const QTextDocumentFragment &other)

コピーコンストラクタ。other フラグメントのコピーを作成します。

[noexcept] QTextDocumentFragment::~QTextDocumentFragment()

文書の断片を破棄する。

[static] QTextDocumentFragment QTextDocumentFragment::fromHtml(const QString &text, const QTextDocument *resourceProvider = nullptr)

与えられたtext 内の HTML の任意の部分を元にQTextDocumentFragment を返します。例えば"<b>bold</b>"は、"bold "というテキストを太字の書式で持つ文書片になります。

提供されたHTMLが、インポートされたスタイルシートなどの外部リソースへの参照を含んでいる場合、それらはresourceProvider を通して読み込まれます。

[static, since 6.4] QTextDocumentFragment QTextDocumentFragment::fromMarkdown(const QString &markdown, QTextDocument::MarkdownFeatures features = QTextDocument::MarkdownDialectGitHub)

指定されたmarkdown テキストをもとに、指定されたfeaturesQTextDocumentFragment を返します。デフォルトは GitHub 方言です。

フォーマットは可能な限り保持されます。例えば、**bold** は "bold" というテキストを太字の文字スタイルで含むドキュメントフラグメントになります。

注意: 外部リソースの読み込みはサポートされていません。

この関数は Qt 6.4 で導入されました。

[static] QTextDocumentFragment QTextDocumentFragment::fromPlainText(const QString &plainText)

与えられたplainText を含む文書断片を返す。

このようなフラグメントをQTextDocument に挿入するときは、挿入に使われたQTextCursor の現在の文字書式がテキストの書式として使われます。

bool QTextDocumentFragment::isEmpty() const

フラグメントが空の場合はtrue を返し、それ以外の場合はfalse を返す。

QString QTextDocumentFragment::toHtml() const

ドキュメント片の内容を HTML として返します。

toPlainText()、toMarkdown() およびQTextDocument::toHtml()も参照 ください。

[since 6.4] QString QTextDocumentFragment::toMarkdown(QTextDocument::MarkdownFeatures features = QTextDocument::MarkdownDialectGitHub) const

ドキュメント片の内容を、指定したfeatures で Markdown として返します。デフォルトはGitHub方言です。

この関数は Qt 6.4 で導入されました。

toPlainText() およびQTextDocument::toMarkdown()も参照してください

QString QTextDocumentFragment::toPlainText() const

この関数はtoRawText() と同じものを返しますが、いくつかの unicode 文字を ASCII の代替文字に置き換えます。特に、改行なしスペース (U+00A0) は通常のスペース (U+0020) に置き換えられ、段落区切り (U+2029) と行区切り (U+2028) はともに改行 (U+000A) に置き換えられます。文書の正確な内容が必要な場合は、代わりにtoRawText() を使う。

toHtml()、toMarkdown()、toRawText()も参照

[since 6.4] QString QTextDocumentFragment::toRawText() const

ドキュメントフラグメントのテキストを生のテキストとして(つまり、フォーマット情報を含まない)返します。

この関数は Qt 6.4 で導入されました。

toHtml(),toMarkdown(),toPlainText()も参照してください

QTextDocumentFragment &QTextDocumentFragment::operator=(const QTextDocumentFragment &other)

このフラグメントにother フラグメントを割り当てます。

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