QQuickTextDocument Class

The QQuickTextDocument class provides access to the QTextDocument of QQuickTextEdit. More...

Header: #include <QQuickTextDocument>
CMake: find_package(Qt6 REQUIRED COMPONENTS Quick)
target_link_libraries(mytarget PRIVATE Qt6::Quick)
qmake: QT += quick
Instantiated By: TextDocument
Inherits: QObject

Properties

Public Functions

QQuickTextDocument(QQuickItem *parent)
QString errorString() const
bool isModified() const
(preliminary) void save()
(preliminary) void saveAs(const QUrl &url)
void setModified(bool modified)
void setSource(const QUrl &url)
(since 6.7) void setTextDocument(QTextDocument *document)
QUrl source() const
QQuickTextDocument::Status status() const
QTextDocument *textDocument() const

Signals

(preliminary) void errorStringChanged()
(preliminary) void modifiedChanged()
(preliminary) void sourceChanged()
(preliminary) void statusChanged()
(since 6.7) void textDocumentChanged()

Detailed Description

This class provides access to the QTextDocument of QQuickTextEdit elements. This is provided to allow usage of the Rich Text Processing functionalities of Qt, including document modifications. It can also be used to output content, for example with QTextDocumentWriter, or provide additional formatting, for example with QSyntaxHighlighter.

Property Documentation

[read-only, preliminary] errorString : const QString

This property is under development and is subject to change.

This property holds a human-readable string describing the error that occurred during loading or saving, if any

By default this string is empty.

This property was introduced in Qt 6.7.

Access functions:

QString errorString() const

Notifier signal:

See also status, source, save(), and saveAs().

[preliminary] modified : bool

This property is under development and is subject to change.

This property holds whether the document has been modified by the user

This property holds whether the document has been modified by the user since the last time it was loaded or saved. By default, this property is false.

As with QTextDocument::modified, you can set the modified property: for example, set it to false to allow setting the source property to a different URL (thus discarding the user's changes).

This property was introduced in Qt 6.7.

Access functions:

bool isModified() const
void setModified(bool modified)

Notifier signal:

See also QTextDocument::modified.

[preliminary] source : QUrl

This property is under development and is subject to change.

This property holds the URL from which to load document contents

QQuickTextDocument can handle any text format supported by Qt, loaded from any URL scheme supported by Qt.

The source property cannot be changed while the document's modified state is true. If the user has modified the document contents, you should prompt the user whether to save(), or else discard changes by setting modified to false before setting the source property to a different URL.

This property was introduced in Qt 6.7.

Access functions:

QUrl source() const
void setSource(const QUrl &url)

Notifier signal:

void sourceChanged()

See also QTextDocumentWriter::supportedDocumentFormats().

[read-only, preliminary] status : const Status

This property is under development and is subject to change.

This property holds the status of document loading or saving

This property holds the status of document loading or saving. It can be one of:

ConstantDescription
NullNo file has been loaded
LoadingReading from source has begun
LoadedReading has successfully finished
SavingFile writing has begun after save() or saveAs()
SavedWriting has successfully finished
ReadErrorAn error occurred while reading from source
WriteErrorAn error occurred in save() or saveAs()
NonLocalFileErrorsaveAs() was called with a URL pointing to a remote resource rather than a local file

This property was introduced in Qt 6.7.

Access functions:

QQuickTextDocument::Status status() const

Notifier signal:

void statusChanged()

See also errorString, source, save(), and saveAs().

Member Function Documentation

QQuickTextDocument::QQuickTextDocument(QQuickItem *parent)

Constructs a QQuickTextDocument object with parent as the parent object.

[signal, preliminary] void QQuickTextDocument::errorStringChanged()

This function is under development and is subject to change.

Note: Notifier signal for property errorString.

[signal, preliminary] void QQuickTextDocument::modifiedChanged()

This function is under development and is subject to change.

Note: Notifier signal for property modified.

[invokable, preliminary] void QQuickTextDocument::save()

This function is under development and is subject to change.

Saves the contents to the same file and format specified by source.

Note: You can save only to a file on a mounted filesystem.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

This function was introduced in Qt 6.7.

See also source and saveAs().

[invokable, preliminary] void QQuickTextDocument::saveAs(const QUrl &url)

This function is under development and is subject to change.

Saves the contents to the file and format specified by url.

The file extension in url specifies the file format (as determined by QMimeDatabase::mimeTypeForUrl()).

Note: You can save only to a file on a mounted filesystem.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

This function was introduced in Qt 6.7.

See also source and save().

[since 6.7] void QQuickTextDocument::setTextDocument(QTextDocument *document)

Sets the given document.

The caller retains ownership of the document.

This function was introduced in Qt 6.7.

See also textDocument().

[signal, preliminary] void QQuickTextDocument::sourceChanged()

This function is under development and is subject to change.

Note: Notifier signal for property source.

[signal, preliminary] void QQuickTextDocument::statusChanged()

This function is under development and is subject to change.

Note: Notifier signal for property status.

QTextDocument *QQuickTextDocument::textDocument() const

Returns a pointer to the QTextDocument object.

See also setTextDocument().

[signal, since 6.7] void QQuickTextDocument::textDocumentChanged()

This signal is emitted when the underlying QTextDocument is replaced with a different instance.

This function was introduced in Qt 6.7.

See also setTextDocument().