QTextDocumentFragment Class

Die Klasse QTextDocumentFragment repräsentiert ein Stück formatierten Text aus einem QTextDocument. Mehr...

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

Hinweis: Alle Funktionen in dieser Klasse sind reentrant.

Öffentliche Funktionen

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)

Statische öffentliche Mitglieder

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)

Detaillierte Beschreibung

Ein QTextDocumentFragment ist ein Fragment von Rich Text, das in ein QTextDocument eingefügt werden kann. Ein Dokumentfragment kann aus einem QTextDocument, aus einer QTextCursor Auswahl oder aus einem anderen Dokumentfragment erstellt werden. Dokumentfragmente können auch mit den statischen Funktionen fromPlainText() und fromHtml() erstellt werden.

Der Inhalt eines Dokumentfragments kann als Rohtext mit der Funktion toRawText(), als ASCII mit toPlainText(), als HTML mit toHtml() oder als Markdown mit toMarkdown() erhalten werden.

Dokumentation der Mitgliedsfunktionen

QTextDocumentFragment::QTextDocumentFragment()

Konstruiert ein leeres QTextDocumentFragment.

Siehe auch isEmpty().

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

Erzeugt ein QTextDocumentFragment aus der Auswahl von cursor. Wenn der Cursor keine Auswahl hat, ist das erstellte Fragment leer.

Siehe auch isEmpty() und QTextCursor::selection().

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

Konvertiert das angegebene document in ein QTextDocumentFragment. Beachten Sie, dass das QTextDocumentFragment nur den Inhalt des Dokuments speichert, nicht aber Metainformationen wie den Titel des Dokuments.

QTextDocumentFragment::QTextDocumentFragment(const QTextDocumentFragment &other)

Konstruktor kopieren. Erzeugt eine Kopie des Fragments other.

[noexcept] QTextDocumentFragment::~QTextDocumentFragment()

Zerstört das Dokumentfragment.

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

Gibt ein QTextDocumentFragment zurück, das auf einem beliebigen HTML-Fragment im angegebenen text basiert. Die Formatierung wird so weit wie möglich beibehalten; zum Beispiel wird "<b>fett</b>" zu einem Dokumentfragment mit dem Text "fett" mit einem fetten Zeichenformat.

Enthält das angegebene HTML Verweise auf externe Ressourcen wie z.B. importierte Stylesheets, so werden diese über die resourceProvider geladen.

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

Gibt ein QTextDocumentFragment basierend auf dem angegebenen markdown Text mit dem angegebenen features zurück. Der Standard ist der GitHub-Dialekt.

Die Formatierung wird so weit wie möglich beibehalten; zum Beispiel wird **bold** zu einem Dokumentfragment, das den Text "bold" mit einem fetten Zeichenstil enthält.

Hinweis: Das Laden externer Ressourcen wird nicht unterstützt.

Diese Funktion wurde in Qt 6.4 eingeführt.

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

Gibt ein Dokumentfragment zurück, das das angegebene plainText enthält.

Beim Einfügen eines solchen Fragments in ein QTextDocument wird das aktuelle Zeichenformat des zum Einfügen verwendeten QTextCursor als Format für den Text verwendet.

bool QTextDocumentFragment::isEmpty() const

Gibt true zurück, wenn das Fragment leer ist; andernfalls wird false zurückgegeben.

QString QTextDocumentFragment::toHtml() const

Gibt den Inhalt des Dokumentfragments als HTML zurück.

Siehe auch toPlainText(), toMarkdown(), und QTextDocument::toHtml().

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

Gibt den Inhalt des Dokumentfragments als Markdown zurück, mit dem angegebenen features. Die Vorgabe ist der GitHub-Dialekt.

Diese Funktion wurde in Qt 6.4 eingeführt.

Siehe auch toPlainText() und QTextDocument::toMarkdown().

QString QTextDocumentFragment::toPlainText() const

Diese Funktion gibt dasselbe zurück wie toRawText(), ersetzt aber einige Unicode-Zeichen durch ASCII-Alternativen. Insbesondere wird das Leerzeichen ohne Umbruch (U+00A0) durch ein reguläres Leerzeichen (U+0020) ersetzt, und sowohl Absatz- (U+2029) als auch Zeilentrenner (U+2028) werden durch Zeilenumbruch (U+000A) ersetzt. Wenn Sie den genauen Inhalt des Dokuments benötigen, verwenden Sie stattdessen toRawText().

Siehe auch toHtml(), toMarkdown(), und toRawText().

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

Gibt den Text des Dokumentfragments als Rohtext (d.h. ohne Formatierungsinformationen) zurück.

Diese Funktion wurde in Qt 6.4 eingeführt.

Siehe auch toHtml(), toMarkdown(), und toPlainText().

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

Weist das Fragment other diesem Fragment zu.

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