QTextDocument 类保持格式化文本。 更多...
头: | #include <QTextDocument> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui) |
qmake: | QT += gui |
继承: | QObject |
注意: 此类的所有函数 可重入 .
enum | FindFlag { FindBackward, FindCaseSensitively, FindWholeWords } |
flags | FindFlags |
flags | MarkdownFeatures |
enum | MetaInformation { DocumentTitle, DocumentUrl, CssMedia } |
ResourceProvider | |
enum | ResourceType { UnknownResource, HtmlResource, ImageResource, StyleSheetResource, MarkdownResource, UserResource } |
enum | Stacks { UndoStack, RedoStack, UndoAndRedoStacks } |
|
|
QTextDocument (QObject * parent = nullptr) | |
QTextDocument (const QString & text , QObject * parent = nullptr) | |
virtual | ~QTextDocument () |
void | addResource (int type , const QUrl & name , const QVariant & resource ) |
void | adjustSize () |
QList<QTextFormat> | allFormats () const |
int | availableRedoSteps () const |
int | availableUndoSteps () const |
QUrl | baseUrl () const |
qreal | baselineOffset () const |
QTextBlock | begin () const |
int | blockCount () const |
QChar | characterAt (int pos ) const |
int | characterCount () const |
virtual void | clear () |
void | clearUndoRedoStacks (QTextDocument::Stacks stacksToClear = UndoAndRedoStacks) |
QTextDocument * | clone (QObject * parent = nullptr) const |
Qt::CursorMoveStyle | defaultCursorMoveStyle () const |
QFont | defaultFont () const |
QString | defaultStyleSheet () const |
QTextOption | defaultTextOption () const |
QAbstractTextDocumentLayout * | documentLayout () const |
qreal | documentMargin () const |
void | drawContents (QPainter * p , const QRectF & rect = QRectF()) |
QTextBlock | end () const |
QTextCursor | find (const QString & subString , const QTextCursor & cursor , QTextDocument::FindFlags options = FindFlags()) const |
QTextCursor | find (const QString & subString , int position = 0, QTextDocument::FindFlags options = FindFlags()) const |
QTextCursor | find (const QRegularExpression & expr , int from = 0, QTextDocument::FindFlags options = FindFlags()) const |
QTextCursor | find (const QRegularExpression & expr , const QTextCursor & cursor , QTextDocument::FindFlags options = FindFlags()) const |
QTextBlock | findBlock (int pos ) const |
QTextBlock | findBlockByLineNumber (int lineNumber ) const |
QTextBlock | findBlockByNumber (int blockNumber ) const |
QTextBlock | firstBlock () const |
qreal | idealWidth () const |
qreal | indentWidth () const |
bool | isEmpty () const |
bool | isLayoutEnabled () const |
bool | isModified () const |
bool | isRedoAvailable () const |
bool | isUndoAvailable () const |
bool | isUndoRedoEnabled () const |
QTextBlock | lastBlock () const |
int | lineCount () const |
void | markContentsDirty (int position , int length ) |
int | maximumBlockCount () const |
QString | metaInformation (QTextDocument::MetaInformation info ) const |
QTextObject * | object (int objectIndex ) const |
QTextObject * | objectForFormat (const QTextFormat & f ) const |
int | pageCount () const |
QSizeF | pageSize () const |
void | print (QPagedPaintDevice * printer ) const |
void | redo (QTextCursor * cursor ) |
QVariant | resource (int type , const QUrl & name ) const |
QTextDocument::ResourceProvider | resourceProvider () const |
int | revision () const |
QTextFrame * | rootFrame () const |
void | setBaseUrl (const QUrl & url ) |
void | setBaselineOffset (qreal baseline ) |
void | setDefaultCursorMoveStyle (Qt::CursorMoveStyle style ) |
void | setDefaultFont (const QFont & font ) |
void | setDefaultStyleSheet (const QString & sheet ) |
void | setDefaultTextOption (const QTextOption & option ) |
void | setDocumentLayout (QAbstractTextDocumentLayout * layout ) |
void | setDocumentMargin (qreal margin ) |
void | setHtml (const QString & html ) |
void | setIndentWidth (qreal width ) |
void | setLayoutEnabled (bool b ) |
void | setMarkdown (const QString & markdown , QTextDocument::MarkdownFeatures features = MarkdownDialectGitHub) |
void | setMaximumBlockCount (int maximum ) |
void | setMetaInformation (QTextDocument::MetaInformation info , const QString & string ) |
void | setPageSize (const QSizeF & size ) |
void | setPlainText (const QString & text ) |
void | setResourceProvider (const QTextDocument::ResourceProvider & provider ) |
void | setSubScriptBaseline (qreal baseline ) |
void | setSuperScriptBaseline (qreal baseline ) |
void | setTextWidth (qreal width ) |
void | setUndoRedoEnabled (bool enable ) |
void | setUseDesignMetrics (bool b ) |
QSizeF | size () const |
qreal | subScriptBaseline () const |
qreal | superScriptBaseline () const |
qreal | textWidth () const |
QString | toHtml () const |
QString | toMarkdown (QTextDocument::MarkdownFeatures features = MarkdownDialectGitHub) const |
QString | toPlainText () const |
QString | toRawText () const |
void | undo (QTextCursor * cursor ) |
bool | useDesignMetrics () const |
void | redo () |
void | setModified (bool m = true) |
void | undo () |
void | baseUrlChanged (const QUrl & url ) |
void | blockCountChanged (int newBlockCount ) |
void | contentsChange (int position , int charsRemoved , int charsAdded ) |
void | contentsChanged () |
void | cursorPositionChanged (const QTextCursor & cursor ) |
void | documentLayoutChanged () |
void | modificationChanged (bool changed ) |
void | redoAvailable (bool available ) |
void | undoAvailable (bool available ) |
void | undoCommandAdded () |
QTextDocument::ResourceProvider | defaultResourceProvider () |
void | setDefaultResourceProvider (const QTextDocument::ResourceProvider & provider ) |
virtual QTextObject * | createObject (const QTextFormat & format ) |
virtual QVariant | loadResource (int type , const QUrl & name ) |
QTextDocument 是结构化富文本文档容器,提供对样式化文本和各种类型的文档元素 (譬如:列表、表格、帧及图像) 的支持。可以创建它们为用于 QTextEdit ,或独立使用。
Each document element is described by an associated format object. Each format object is treated as a unique object by QTextDocuments, and can be passed to objectForFormat () to obtain the document element that it is applied to.
A QTextDocument can be edited programmatically using a QTextCursor , and its contents can be examined by traversing the document structure. The entire document structure is stored as a hierarchy of document elements beneath the root frame, found with the rootFrame () function. Alternatively, if you just want to iterate over the textual contents of the document you can use begin (), end (),和 findBlock () to retrieve text blocks that you can examine and iterate over.
The layout of a document is determined by the documentLayout (); you can create your own QAbstractTextDocumentLayout subclass and set it using setDocumentLayout () if you want to use your own layout logic. The document's title and other meta-information can be obtained by calling the metaInformation () function. For documents that are exposed to users through the QTextEdit class, the document title is also available via the QTextEdit::documentTitle () 函数。
The toPlainText () 和 toHtml () convenience functions allow you to retrieve the contents of the document as plain text and HTML. The document's text can be searched using the find () 函数。
Undo/redo of operations performed on the document can be controlled using the setUndoRedoEnabled () function. The undo/redo system can be controlled by an editor widget through the undo () 和 redo () slots; the document also provides contentsChanged (), undoAvailable (),和 redoAvailable () signals that inform connected editor widgets about the state of the undo/redo system. The following are the undo/redo operations of a QTextDocument:
另请参阅 QTextCursor , QTextEdit , 富文本处理 ,和文本对象范例。
此枚举描述的选项可用于 QTextDocument 的 find 函数。可以将以下列出中选项 OR 在一起:
常量 | 值 | 描述 |
---|---|---|
QTextDocument::FindBackward
|
0x00001
|
向后而不是向前搜索。 |
QTextDocument::FindCaseSensitively
|
0x00002
|
默认情况下,find 工作不区分大小写。指定此选项会将查找操作行为更改为区分大小写。 |
QTextDocument::FindWholeWords
|
0x00004
|
使查找只匹配完整单词。 |
FindFlags 类型是 typedef 对于 QFlags <FindFlag>。它存储 FindFlag 值的 OR 组合。
此枚举描述可以被添加到文档的元信息的不同类型。
常量 | 值 | 描述 |
---|---|---|
QTextDocument::DocumentTitle
|
0
|
文档标题。 |
QTextDocument::DocumentUrl
|
1
|
文档的 URL。 loadResource () 函数将此 URL 用作基,当加载相关资源时。 |
QTextDocument::CssMedia
|
2
|
This value is used to select the corresponding '@media' rule, if any, from a specified CSS stylesheet when setHtml () is called. This enum value has been introduced in Qt 6.3. |
另请参阅 metaInformation (), setMetaInformation (),和 setHtml ().
[alias, since 6.1]
QTextDocument::
ResourceProvider
Type alias for std::function< QVariant (const QUrl &)>.
该 typedef 在 Qt 6.1 引入。
This enum describes the types of resources that can be loaded by QTextDocument 's loadResource () function or by QTextBrowser::setSource ().
常量 | 值 | 描述 |
---|---|---|
QTextDocument::UnknownResource
|
0
|
No resource is loaded, or the resource type is not known. |
QTextDocument::HtmlResource
|
1
|
资源包含 HTML。 |
QTextDocument::ImageResource
|
2
|
The resource contains image data. Currently supported data types are QMetaType::QPixmap and QMetaType::QImage . If the corresponding variant is of type QMetaType::QByteArray then Qt attempts to load the image using QImage::loadFromData . QMetaType::QIcon is currently not supported. The icon needs to be converted to one of the supported types first, for example using QIcon::pixmap . |
QTextDocument::StyleSheetResource
|
3
|
The resource contains CSS. |
QTextDocument::MarkdownResource
|
4
|
The resource contains Markdown. |
QTextDocument::UserResource
|
100
|
The first available value for user defined resource types. |
另请参阅 loadResource () 和 QTextBrowser::sourceType ().
常量 | 值 | 描述 |
---|---|---|
QTextDocument::UndoStack
|
0x01
|
撤消堆栈。 |
QTextDocument::RedoStack
|
0x02
|
重做堆栈。 |
QTextDocument::UndoAndRedoStacks
|
UndoStack | RedoStack
|
撤消和重做堆栈。 |
This property holds the base URL used to resolve relative resource URLs within the document.
Resource URLs are resolved to be within the same directory as the target of the base URL meaning any portion of the path after the last '/' will be ignored.
Base URL | Relative URL | Resolved URL |
---|---|---|
file:///path/to/content | images/logo.png | file:///path/to/images/logo.png |
file:///path/to/content/ | images/logo.png | file:///path/to/content/images/logo.png |
file:///path/to/content/index.html | images/logo.png | file:///path/to/content/images/logo.png |
file:///path/to/content/images/ | ../images/logo.png | file:///path/to/content/images/logo.png |
访问函数:
QUrl | baseUrl () const |
void | setBaseUrl (const QUrl & url ) |
通知程序信号:
void | baseUrlChanged (const QUrl & url ) |
[read-only]
blockCount
: const
int
此特性保持文档文本块数。
此特性的值在具有表格 (或框架) 的文档中未定义。
默认情况下,若有定义,此特性包含值 1。
访问函数:
int | blockCount () const |
另请参阅 lineCount () 和 characterCount ().
此特性保持用于显示文档文本的默认字体
访问函数:
QFont | defaultFont () const |
void | setDefaultFont (const QFont & font ) |
The default style sheet is applied to all newly HTML formatted text that is inserted into the document, for example using setHtml () 或 QTextCursor::insertHtml ().
样式表需要遵从 CSS 2.1 句法。
注意: Changing the default style sheet does not have any effect to the existing content of the document.
访问函数:
QString | defaultStyleSheet () const |
void | setDefaultStyleSheet (const QString & sheet ) |
另请参阅 支持的 HTML 子集 .
This property holds the default text option will be set on all QTextLayout s in the document.
当 QTextBlock s are created, the defaultTextOption is set on their QTextLayout . This allows setting global properties for the document such as the default word wrap mode.
访问函数:
QTextOption | defaultTextOption () const |
void | setDefaultTextOption (const QTextOption & option ) |
围绕文档的边距。默认为 4。
访问函数:
qreal | documentMargin () const |
void | setDocumentMargin (qreal margin ) |
Returns the width used for text list and text block indenting.
The indent properties of QTextListFormat and QTextBlockFormat specify multiples of this value. The default indent width is 40.
访问函数:
qreal | indentWidth () const |
void | setIndentWidth (qreal width ) |
[since 6.4]
layoutEnabled
:
bool
此特性保持是否 QTextDocument should recalculate the layout after every change
If this property is set to true, any change to the document triggers a layout, which makes everything work as expected but takes time.
Temporarily disabling the layout can save time when making multiple changes (not just text content, but also default font, default text option....) so that the document is only laid out once at the end. This can be useful when the text width or page size isn't yet known, for instance.
默认情况下,此特性为
true
.
该特性在 Qt 6。4 引入。
访问函数:
bool | isLayoutEnabled () const |
void | setLayoutEnabled (bool b ) |
另请参阅 setTextWidth .
指定对文档的块数限制。
指定文档可能拥有的最大块数。若采用此特性的指定文档有更多块,则块被移除从文档开头。
文档的负值 (或零值) 指定可能包含无限数量的块。
默认值为 0。
注意:设置此特性会立即将限制应用于文档内容。
设置此特性还会禁用撤消、重做历史。
此特性在具有表格 (或框架) 的文档中未定义。
访问函数:
int | maximumBlockCount () const |
void | setMaximumBlockCount (int maximum ) |
此特性保持文档是否已被用户修改
默认情况下,此特性为
false
.
访问函数:
bool | isModified () const |
void | setModified (bool m = true) |
另请参阅 modificationChanged ().
This property holds the page size that should be used for laying out the document
The units are determined by the underlying paint device. The size is measured in logical pixels when painting to the screen, and in points (1/72 inch) when painting to a printer.
By default, for a newly-created, empty document, this property contains an undefined size.
访问函数:
QSizeF | pageSize () const |
void | setPageSize (const QSizeF & size ) |
另请参阅 modificationChanged ().
[read-only]
size
: const
QSizeF
This property holds the actual size of the document. This is equivalent to documentLayout ()->documentSize();
The size of the document can be changed either by setting a text width or setting an entire page size.
Note that the width is always >= pageSize ().width().
By default, for a newly-created, empty document, this property contains a configuration-dependent size.
访问函数:
QSizeF | size () const |
另请参阅 setTextWidth (), setPageSize (),和 idealWidth ().
The text width specifies the preferred width for text in the document. If the text (or content in general) is wider than the specified with it is broken into multiple lines and grows vertically. If the text cannot be broken into multiple lines to fit into the specified text width it will be larger and the size () 和 idealWidth () property will reflect that.
If the text width is set to -1 then the text will not be broken into multiple lines unless it is enforced through an explicit line break or a new paragraph.
默认值为 -1。
Setting the text width will also set the page height to -1, causing the document to grow or shrink vertically in a continuous way. If you want the document layout to break the text into multiple pages then you have to set the pageSize 特性代替。
访问函数:
qreal | textWidth () const |
void | setTextWidth (qreal width ) |
另请参阅 size (), idealWidth (),和 pageSize ().
This property holds whether undo/redo are enabled for this document
This defaults to true. If disabled, the undo stack is cleared and no items will be added to it.
访问函数:
bool | isUndoRedoEnabled () const |
void | setUndoRedoEnabled (bool enable ) |
This property holds whether the document uses design metrics of fonts to improve the accuracy of text layout
If this property is set to true, the layout will use design metrics. Otherwise, the metrics of the paint device as set on QAbstractTextDocumentLayout::setPaintDevice () will be used.
Using design metrics makes a layout have a width that is no longer dependent on hinting and pixel-rounding. This means that WYSIWYG text layout becomes possible because the width scales much more linearly based on paintdevice metrics than it would otherwise.
默认情况下,此特性为
false
.
访问函数:
bool | useDesignMetrics () const |
void | setUseDesignMetrics (bool b ) |
[explicit]
QTextDocument::
QTextDocument
(
QObject
*
parent
= nullptr)
构造空的 QTextDocument 采用给定 parent .
[explicit]
QTextDocument::
QTextDocument
(const
QString
&
text
,
QObject
*
parent
= nullptr)
Constructs a QTextDocument containing the plain (unformatted) text specified, and with the given parent .
[virtual noexcept]
QTextDocument::
~QTextDocument
()
销毁文档。
添加资源 resource to the resource cache, using type and name as identifiers. type should be a value from QTextDocument::ResourceType .
For example, you can add an image as a resource in order to reference it from within the document:
document->addResource(QTextDocument::ImageResource, QUrl("mydata://image.png"), QVariant(image));
The image can be inserted into the document using the QTextCursor API:
QTextImageFormat imageFormat; imageFormat.setName("mydata://image.png"); cursor.insertImage(imageFormat);
Alternatively, you can insert images using the HTML
img
tag:
editor->append("<img src=\"mydata://image.png\" />");
把文档调节到合理大小。
另请参阅 idealWidth (), textWidth ,和 size .
Returns a list of text formats for all the formats used in the document.
返回可用的重做步骤数。
另请参阅 isRedoAvailable ().
返回可用的撤消步骤数。
另请参阅 isUndoAvailable ().
[since 6.0]
qreal
QTextDocument::
baselineOffset
() const
Returns the baseline offset in % used in the document layout.
该函数在 Qt 6.0 引入。
另请参阅 setBaselineOffset (), setSubScriptBaseline (), subScriptBaseline (), setSuperScriptBaseline (),和 superScriptBaseline ().
返回文档的第一文本块。
另请参阅 firstBlock ().
[signal]
void
QTextDocument::
blockCountChanged
(
int
newBlockCount
)
This signal is emitted when the total number of text blocks in the document changes. The value passed in newBlockCount is the new total.
返回字符位于位置 pos ,或 null 字符若位置超出范围。
另请参阅 characterCount ().
返回此文档的字符数。
注意: As a QTextDocument 始终包含至少一 QChar::ParagraphSeparator ,此方法将至少返回 1。
另请参阅 blockCount () 和 characterAt ().
[virtual]
void
QTextDocument::
clear
()
清理文档。
清零堆栈,指定通过 stacksToClear .
此方法清零撤消堆栈、重做堆栈或两者 (默认) 中的任何命令。若命令被清零,会发射适当信号 QTextDocument::undoAvailable () 或 QTextDocument::redoAvailable ().
另请参阅 QTextDocument::undoAvailable () 和 QTextDocument::redoAvailable ().
创建新的 QTextDocument that is a copy of this text document. parent is the parent of the returned text document.
[signal]
void
QTextDocument::
contentsChange
(
int
position
,
int
charsRemoved
,
int
charsAdded
)
此信号被发射每当文档内容改变时;例如,当插入 (或删除) 文本 (或应用格式) 时。
Information is provided about the position of the character in the document where the change occurred, the number of characters removed ( charsRemoved ), and the number of characters added ( charsAdded ).
The signal is emitted before the document's layout manager is notified about the change. This hook allows you to implement syntax highlighting for the document.
另请参阅 QAbstractTextDocumentLayout::documentChanged () 和 contentsChanged ().
[signal]
void
QTextDocument::
contentsChanged
()
此信号被发射每当文档内容改变时;例如,当插入 (或删除) 文本 (或应用格式) 时。
另请参阅 contentsChange ().
[virtual protected]
QTextObject
*QTextDocument::
createObject
(const
QTextFormat
&
format
)
创建并返回新文档对象 ( QTextObject ),基于给定 format .
QTextObjects will always get created through this method, so you must reimplement it if you use custom text objects inside your document.
[signal]
void
QTextDocument::
cursorPositionChanged
(const
QTextCursor
&
cursor
)
This signal is emitted whenever the position of a cursor changed due to an editing operation. The cursor that changed is passed in cursor 。若文档用于 QTextEdit class and you need a signal when the cursor is moved with the arrow keys you can use the cursorPositionChanged () signal in QTextEdit .
The default cursor movement style is used by all QTextCursor objects created from the document. The default is Qt::LogicalMoveStyle .
另请参阅 setDefaultCursorMoveStyle ().
Returns the default font to be used in the document layout.
注意: Getter function for property defaultFont.
另请参阅 setDefaultFont ().
[static, since 6.1]
QTextDocument::ResourceProvider
QTextDocument::
defaultResourceProvider
()
Returns the default resource provider.
该函数在 Qt 6.1 引入。
另请参阅 setDefaultResourceProvider (), resourceProvider (),和 loadResource ().
The default text option is used on all QTextLayout objects in the document. This allows setting global properties for the document such as the default word wrap mode.
注意: Getter function for property defaultTextOption.
另请参阅 setDefaultTextOption ().
返回此文档的文档布局。
另请参阅 setDocumentLayout ().
[signal]
void
QTextDocument::
documentLayoutChanged
()
This signal is emitted when a new document layout is set.
另请参阅 setDocumentLayout ().
Draws the content of the document with painter p , clipped to rect 。若 rect is a null rectangle (default) then the document is painted unclipped.
此函数返回当遍历时,测试文档结尾的块。
for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next()) std::cout << it.text().toStdString() << "\n";
返回的块无效,表示文档最后块之后的块。可以使用 lastBlock () 以检索文档的最后有效块。
另请参阅 lastBlock ().
查找字符串的下一出现 subString , in the document. The search starts at the position of the given cursor , and proceeds forwards through the document unless specified otherwise in the search options. The options control the type of search performed.
返回光标具有匹配选中若 subString was found; otherwise returns a null cursor.
若给定 cursor has a selection, the search begins after the selection; otherwise it begins at the cursor's position.
By default the search is case insensitive, and can match text anywhere in the document.
这是重载函数。
查找字符串的下一出现 subString , in the document. The search starts at the given position , and proceeds forwards through the document unless specified otherwise in the search options. The options control the type of search performed.
返回光标具有匹配选中若 subString was found; otherwise returns a null cursor.
若 position is 0 (the default) the search begins from the beginning of the document; otherwise it begins at the specified position.
Finds the next occurrence that matches the given regular expression, expr , within the same paragraph in the document.
The search starts at the given from position, and proceeds forwards through the document unless specified otherwise in the search options. The options control the type of search performed.
Returns a cursor with the match selected if a match was found; otherwise returns a null cursor.
若 from position is 0 (the default) the search begins from the beginning of the document; otherwise it begins at the specified position.
Finds the next occurrence that matches the given regular expression, expr , within the same paragraph in the document.
The search starts at the position of the given cursor , and proceeds forwards through the document unless specified otherwise in the search options. The options control the type of search performed.
Returns a cursor with the match selected if a match was found; otherwise returns a null cursor.
若给定 cursor has a selection, the search begins after the selection; otherwise it begins at the cursor's position.
By default the search is case insensitive, and can match text anywhere in the document.
返回文本块包含 pos 的字符。
返回文本块包含指定 lineNumber .
另请参阅 QTextBlock::firstLineNumber ().
返回文本块采用指定 blockNumber .
另请参阅 QTextBlock::blockNumber ().
返回文档的第一文本块。
返回文本文档的理想宽度。理想宽度是不考虑可选对齐的文档实际使用宽度。它终 <= size ().width().
另请参阅 adjustSize () 和 textWidth .
返回
true
若文档为空;否则返回
false
.
返回
true
若重做是可用的;否则返回
false
.
另请参阅 isUndoAvailable () 和 availableRedoSteps ().
返回
true
若撤消可用;否则返回
false
.
另请参阅 isRedoAvailable () 和 availableUndoSteps ().
返回文档的最后 (有效) 文本块。
Returns the number of lines of this document (if the layout supports this). Otherwise, this is identical to the number of blocks.
另请参阅 blockCount () 和 characterCount ().
[virtual protected invokable]
QVariant
QTextDocument::
loadResource
(
int
type
, const
QUrl
&
name
)
加载数据按指定 type 从资源采用给定 name .
This function is called by the rich text engine to request data that isn't directly stored by QTextDocument , but still associated with it. For example, images are referenced indirectly by the name attribute of a QTextImageFormat 对象。
When called by Qt, type is one of the values of QTextDocument::ResourceType .
若 QTextDocument is a child object of a QObject that has an invokable loadResource method such as QTextEdit , QTextBrowser 或 QTextDocument itself then the default implementation tries to retrieve the data from the parent.
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
另请参阅 QTextDocument::ResourceProvider .
Marks the contents specified by the given position and length as "dirty", informing the document that it needs to be laid out again.
Returns meta information about the document of the type specified by info .
另请参阅 setMetaInformation ().
[signal]
void
QTextDocument::
modificationChanged
(
bool
changed
)
此信号被发射每当文档的内容以影响修改状态的方式更改时。若 changed 为 true,文档已被修改;否则它为 false。
例如:调用 setModified (false) 在文档,然后插入文本导致发射信号。若撤消该操作,导致文档返回其原始未修改状态,将再次发射信号。
返回的文本对象关联给定 objectIndex .
返回文本对象关联格式 f .
返回此文档中的页数。
将文档打印到给定 printer 。 QPagedPaintDevice must be set up before being used with this function.
This is only a convenience method to print the whole document to the printer.
If the document is already paginated through a specified height in the pageSize () property it is printed as-is.
If the document is not paginated, like for example a document used in a QTextEdit , then a temporary copy of the document is created and the copy is broken into multiple pages according to the size of the paint device's paperRect(). By default a 2 cm margin is set around the document contents. In addition the current page number is printed at the bottom of each page.
另请参阅 QTextEdit::print ().
Redoes the last editing operation on the document if 重做是可用的 .
The provided cursor is positioned at the end of the location where the edition operation was redone.
[slot]
void
QTextDocument::
redo
()
这是重载函数。
Redoes the last editing operation on the document if 重做是可用的 .
[signal]
void
QTextDocument::
redoAvailable
(
bool
available
)
此信号被发射,每当重做操作变为可用时 ( available 为 True) 或不可用 ( available 为 false)。
Returns data of the specified type 从资源采用给定 name .
This function is called by the rich text engine to request data that isn't directly stored by QTextDocument , but still associated with it. For example, images are referenced indirectly by the name attribute of a QTextImageFormat 对象。
Resources are cached internally in the document. If a resource can not be found in the cache, loadResource is called to try to load the resource. loadResource should then use addResource to add the resource to the cache.
若 loadResource does not load the resource, then the resourceProvider and lastly the defaultResourceProvider will be called, if set. Note that the result from the provider will not be added automatically to the cache.
另请参阅 QTextDocument::ResourceType and resourceProvider ().
[since 6.1]
QTextDocument::ResourceProvider
QTextDocument::
resourceProvider
() const
Returns the resource provider for this text document.
该函数在 Qt 6.1 引入。
另请参阅 setResourceProvider (), defaultResourceProvider (),和 loadResource ().
Returns the document's revision (if undo is enabled).
The revision is guaranteed to increase when a document that is not modified is edited.
另请参阅 QTextBlock::revision () 和 isModified ().
Returns the document's root frame.
[since 6.0]
void
QTextDocument::
setBaselineOffset
(
qreal
baseline
)
Sets the base line as a% of font height to use in the document layout to baseline . The default value is 0. A positive value moves up the text, by the corresponding %; a negative value moves it down.
该函数在 Qt 6.0 引入。
另请参阅 baselineOffset (), setSubScriptBaseline (), subScriptBaseline (), setSuperScriptBaseline (),和 superScriptBaseline ().
Sets the default cursor movement style to the given style .
另请参阅 defaultCursorMoveStyle ().
设置默认 font to use in the document layout.
注意: Setter 函数对于特性 defaultFont .
另请参阅 defaultFont ().
[static, since 6.1]
void
QTextDocument::
setDefaultResourceProvider
(const
QTextDocument::ResourceProvider
&
provider
)
将默认资源提供程序设为 provider .
The default provider will be used by all QTextDocuments that don't have an explicit provider set.
该函数在 Qt 6.1 引入。
另请参阅 defaultResourceProvider (), setResourceProvider (),和 loadResource ().
将默认文本选项设为 option .
注意: Setter 函数对于特性 defaultTextOption .
另请参阅 defaultTextOption ().
将文档设为使用给定 layout 。删除先前布局。
另请参阅 documentLayoutChanged ().
Replaces the entire contents of the document with the given HTML-formatted text in the html string. The undo/redo history is reset when this function is called.
The HTML formatting is respected as much as possible; for example, "<b>bold</b> text" will produce text where the first word has a font weight that gives it a bold appearance: " bold text".
To select a css media rule other than the default "screen" rule, use setMetaInformation () with ' CssMedia ' as "info" parameter.
注意: 调用者有责任确保正确解码文本当 QString 包含的 HTML 被创建并传递给 setHtml() 时。
另请参阅 setPlainText (), 支持的 HTML 子集 ,和 setMetaInformation ().
设置 width 用于文本列表和文本块缩进。
The indent properties of QTextListFormat and QTextBlockFormat specify multiples of this value. The default indent width is 40 .
注意: Setter 函数对于特性 indentWidth .
另请参阅 indentWidth ().
Replaces the entire contents of the document with the given Markdown-formatted text in the
markdown
string, with the given
features
supported. By default, all supported GitHub-style Markdown features are included; pass
MarkdownDialectCommonMark
for a more basic parse.
The Markdown formatting is respected as much as possible; for example, "*bold* text" will produce text where the first word has a font weight that gives it an emphasized appearance.
Parsing of HTML included in the markdown string is handled in the same way as in setHtml ; however, Markdown formatting inside HTML blocks is not supported.
Some features of the parser can be enabled or disabled via the features 自变量:
常量 | 描述 |
---|---|
MarkdownNoHTML
|
将丢弃 Markdown 文本中的任何 HTML 标签 |
MarkdownDialectCommonMark
|
剖析器仅支持由 CommonMark 标准化的特征 |
MarkdownDialectGitHub
|
剖析器支持 GitHub 方言 |
默认为
MarkdownDialectGitHub
.
撤消/重做历史被重置,当调用此函数时。
Sets the document's meta information of the type specified by info 到给定 string .
另请参阅 metaInformation ().
Replaces the entire contents of the document with the given plain text . The undo/redo history is reset when this function is called.
另请参阅 setHtml ().
[since 6.1]
void
QTextDocument::
setResourceProvider
(const
QTextDocument::ResourceProvider
&
provider
)
Sets the provider of resources for the text document to provider .
该函数在 Qt 6.1 引入。
另请参阅 resourceProvider () 和 loadResource ().
[since 6.0]
void
QTextDocument::
setSubScriptBaseline
(
qreal
baseline
)
Sets the default subscript's base line as a % of font height to use in the document layout to baseline . The default value is 16.67% (1/6 of height).
该函数在 Qt 6.0 引入。
另请参阅 subScriptBaseline (), setSuperScriptBaseline (), superScriptBaseline (), setBaselineOffset (),和 baselineOffset ().
[since 6.0]
void
QTextDocument::
setSuperScriptBaseline
(
qreal
baseline
)
Sets the default superscript's base line as a % of font height to use in the document layout to baseline . The default value is 50% (1/2 of height).
该函数在 Qt 6.0 引入。
另请参阅 superScriptBaseline (), setSubScriptBaseline (), subScriptBaseline (), setBaselineOffset (),和 baselineOffset ().
[since 6.0]
qreal
QTextDocument::
subScriptBaseline
() const
Returns the superscript's base line as a % of font height used in the document layout.
该函数在 Qt 6.0 引入。
另请参阅 setSubScriptBaseline (), setSuperScriptBaseline (), superScriptBaseline (), setBaselineOffset (),和 baselineOffset ().
[since 6.0]
qreal
QTextDocument::
superScriptBaseline
() const
Returns the superscript's base line as a % of font height used in the document layout.
该函数在 Qt 6.0 引入。
另请参阅 setSuperScriptBaseline (), setSubScriptBaseline (), subScriptBaseline (), setBaselineOffset (),和 baselineOffset ().
Returns a string containing an HTML representation of the document.
The content of the document specifies its encoding to be UTF-8. If you later on convert the returned html string into a byte array for transmission over a network or when saving to disk you should use QString::toUtf8 () to convert the string to a QByteArray .
另请参阅 支持的 HTML 子集 .
Returns a string containing a Markdown representation of the document with the given features , or an empty string if writing fails for any reason.
另请参阅 setMarkdown .
Returns the plain text contained in the document. If you want formatting information use a QTextCursor 代替。
This function returns the same as toRawText (), but will replace some unicode characters with ASCII alternatives. In particular, no-break space (U+00A0) is replaced by a regular space (U+0020), and both paragraph (U+2029) and line (U+2028) separators are replaced by line feed (U+000A). If you need the precise contents of the document, use toRawText () 代替。
注意: Embedded objects, such as images, are represented by a Unicode value U+FFFC (OBJECT REPLACEMENT CHARACTER).
另请参阅 toHtml ().
Returns the raw text contained in the document without any formatting information. If you want formatting information use a QTextCursor 代替。
另请参阅 toPlainText ().
Undoes the last editing operation on the document if undo is available. The provided cursor is positioned at the end of the location where the edition operation was undone.
见 Qt Undo Framework 文档编制了解细节。
另请参阅 undoAvailable () 和 isUndoRedoEnabled ().
[slot]
void
QTextDocument::
undo
()
这是重载函数。
[signal]
void
QTextDocument::
undoAvailable
(
bool
available
)
此信号被发射每当撤消操作变为可用 ( available 为 True) 或不可用 ( available 为 false)。
见 Qt Undo Framework 文档编制了解细节。
另请参阅 undo () 和 isUndoRedoEnabled ().
[signal]
void
QTextDocument::
undoCommandAdded
()
This signal is emitted every time a new level of undo is added to the QTextDocument .