A wrapper around TextEdit 's backing QTextDocument . 更多...
import 语句: | import QtQuick |
实例化: | QQuickTextDocument |
状态: | Preliminary |
This type is under development and is subject to change.
(preliminary)
(preliminary)
(preliminary)
(preliminary)
To load text into the document, set the source property. If the user then modifies the text and wants to save the same document, call save () to save it to the same source again (only if it's a local file ). Or call saveAs () to save it to a different file.
This class cannot be instantiated in QML, but is available from TextEdit::textDocument .
注意: All loading and saving is done synchronously for now. This may block the UI if the source is a slow network drive. This may be improved in future versions of Qt.
注意: This API is considered tech preview and may change in future versions of Qt.
errorString
:
string
|
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; otherwise, an empty string.
This property was introduced in Qt 6.7.
另请参阅 status , source , save (),和 saveAs ().
modified
:
bool
|
This property is under development and is subject to change.
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
.
就像
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.
另请参阅 QTextDocument::modified .
source
:
url
|
This property is under development and is subject to change.
QQuickTextDocument can handle any text format supported by Qt, loaded from any URL scheme supported by Qt.
The URL may be absolute, or relative to the URL of the component.
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 = false
before setting the source property to a different URL.
This property was introduced in Qt 6.7.
另请参阅 QTextDocumentWriter::supportedDocumentFormats ().
status
:
enumeration
|
This property is under development and is subject to change.
This property holds the status of document loading or saving. It can be one of:
常量 | 描述 |
---|---|
TextDocument.Null
|
No file has been loaded |
TextDocument.Loading
|
Reading from source has begun |
TextDocument.Loaded
|
Reading has successfully finished |
TextDocument.Saving
|
File writing has begun after save () 或 saveAs () |
TextDocument.Saved
|
Writing has successfully finished |
TextDocument.ReadError
|
An error occurred while reading from source |
TextDocument.WriteError
|
An error occurred in save () 或 saveAs () |
TextDocument.NonLocalFileError
|
saveAs () was called with a URL pointing to a remote resource rather than a local file |
Use this status to provide an update or respond to the status change in some way. For example, you could:
State { name: 'loaded' when: textEdit.textDocument.status == textEdit.textDocument.Loaded }
onStatusChanged
signal handler:
TextEdit { onStatusChanged : { if ( textDocument . status === textDocument . Loaded ) console . log ( 'Loaded' ) } }
TextEdit { id: edit width: 300 height: 200 textFormat: TextEdit.MarkdownText textDocument.source: "example.md" wrapMode: TextEdit.WordWrap Text { anchors { bottom: parent.bottom right: parent.right } color: edit.textDocument.status === TextDocument.Loaded ? "darkolivegreen" : "tomato" text: switch (edit.textDocument.status) { case TextDocument.Loading: return qsTr("Loading ") + edit.textDocument.source case TextDocument.Loaded: return qsTr("Loaded ") + edit.textDocument.source default: return edit.textDocument.errorString } } }
This property was introduced in Qt 6.7.
另请参阅 errorString , source , save (),和 saveAs ().
|
This method is under development and is subject to change.
Saves the contents to the same file and format specified by source .
注意: You can save only to a file on a mounted filesystem .
This method was introduced in Qt 6.7.
|
This method 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 ()).
注意: You can save only to a file on a mounted filesystem .
This method was introduced in Qt 6.7.