QTextDocument class holds formatted text. 更多...
头: | #include <QTextDocument> |
qmake: | QT += gui |
继承: | QObject |
注意: 此类的所有函数 可重入 .
enum | FindFlag { FindBackward, FindCaseSensitively, FindWholeWords } |
flags | FindFlags |
enum | MetaInformation { DocumentTitle, DocumentUrl } |
enum | ResourceType { HtmlResource, ImageResource, StyleSheetResource, UserResource } |
enum | Stacks { UndoStack, RedoStack, UndoAndRedoStacks } |
|
|
QTextDocument (QObject * parent = Q_NULLPTR) | |
QTextDocument (const QString & text , QObject * parent = Q_NULLPTR) | |
~QTextDocument () | |
void | addResource (int type , const QUrl & name , const QVariant & resource ) |
void | adjustSize () |
QVector<QTextFormat> | allFormats () const |
int | availableRedoSteps () const |
int | availableUndoSteps () const |
QUrl | baseUrl () const |
QTextBlock | begin () const |
int | blockCount () const |
QChar | characterAt (int pos ) const |
int | characterCount () const |
virtual void | clear () |
void | clearUndoRedoStacks (Stacks stacksToClear = UndoAndRedoStacks) |
QTextDocument * | clone (QObject * parent = Q_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 , FindFlags options = FindFlags()) const |
QTextCursor | find (const QString & subString , int position = 0, FindFlags options = FindFlags()) const |
QTextCursor | find (const QRegExp & expr , int from = 0, FindFlags options = FindFlags()) const |
QTextCursor | find (const QRegExp & expr , const QTextCursor & cursor , FindFlags options = FindFlags()) const |
QTextCursor | find (const QRegularExpression & expr , int from = 0, FindFlags options = FindFlags()) const |
QTextCursor | find (const QRegularExpression & expr , const QTextCursor & cursor , 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 | 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 (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 |
int | revision () const |
QTextFrame * | rootFrame () const |
void | setBaseUrl (const QUrl & url ) |
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 | setMaximumBlockCount (int maximum ) |
void | setMetaInformation (MetaInformation info , const QString & string ) |
void | setPageSize (const QSizeF & size ) |
void | setPlainText (const QString & text ) |
void | setTextWidth (qreal width ) |
void | setUndoRedoEnabled (bool enable ) |
void | setUseDesignMetrics (bool b ) |
QSizeF | size () const |
qreal | textWidth () const |
QString | toHtml (const QByteArray & encoding = QByteArray()) 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 () |
virtual QTextObject * | createObject (const QTextFormat & format ) |
virtual QVariant | loadResource (int type , const QUrl & name ) |
QTextDocument class holds formatted text.
QTextDocument is a container for structured rich text documents, providing support for styled text and various types of document elements, such as lists, tables, frames, and images. They can be created for use in a 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 () 函数。
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 , 富文本处理 ,和 文本对象范例 .
This enum describes the options available to QTextDocument 's find function. The options can be OR-ed together from the following list:
常量 | 值 | 描述 |
---|---|---|
QTextDocument::FindBackward
|
0x00001
|
向后而不是向前搜索。 |
QTextDocument::FindCaseSensitively
|
0x00002
|
By default find works case insensitive. Specifying this option changes the behaviour to a case sensitive find operation. |
QTextDocument::FindWholeWords
|
0x00004
|
Makes find match only complete words. |
FindFlags 类型是 typedef 对于 QFlags <FindFlag>。它存储 FindFlag 值的 OR 组合。
This enum describes the different types of meta information that can be added to a document.
常量 | 值 | 描述 |
---|---|---|
QTextDocument::DocumentTitle
|
0
|
文档标题。 |
QTextDocument::DocumentUrl
|
1
|
The url of the document. The loadResource () function uses this url as the base when loading relative resources. |
另请参阅 metaInformation () 和 setMetaInformation ().
This enum describes the types of resources that can be loaded by QTextDocument 's loadResource () 函数。
常量 | 值 | 描述 |
---|---|---|
QTextDocument::HtmlResource
|
1
|
The resource contains HTML. |
QTextDocument::ImageResource
|
2
|
The resource contains image data. Currently supported data types are QVariant::Pixmap and QVariant::Image. If the corresponding variant is of type QVariant::ByteArray then Qt attempts to load the image using QImage::loadFromData . QVariant::Icon 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::UserResource
|
100
|
The first available value for user defined resource types. |
另请参阅 loadResource ().
常量 | 值 | 描述 |
---|---|---|
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 |
该特性在 Qt 5.3 引入。
访问函数:
QUrl | baseUrl () const |
void | setBaseUrl (const QUrl & url ) |
通知程序信号:
void | baseUrlChanged (const QUrl & url ) |
返回文档的文本块数。
此特性的值在具有表格 (或框架) 的文档中未定义。
默认情况下,若已定义,此特性包含 1 值。
该特性在 Qt 4.2 引入。
访问函数:
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.
该特性在 Qt 4.2 引入。
访问函数:
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。
该特性在 Qt 4.5 引入。
访问函数:
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.
该特性在 Qt 4.4 引入。
访问函数:
qreal | indentWidth () const |
void | setIndentWidth (qreal width ) |
指定对文档的块数限制。
指定文档可能拥有的最大块数。若采用此特性的指定文档有更多块,则块被移除从文档开头。
文档的负值 (或零值) 指定可能包含无限数量的块。
默认值为 0。
注意:设置此特性会立即将限制应用于文档内容。
设置此特性还会禁用撤消、重做历史。
此特性在具有表格 (或框架) 的文档中未定义。
该特性在 Qt 4.2 引入。
访问函数:
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 ().
Returns 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.
该特性在 Qt 4.2 引入。
访问函数:
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 特性代替。
该特性在 Qt 4.2 引入。
访问函数:
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
.
该特性在 Qt 4.1 引入。
访问函数:
bool | useDesignMetrics () const |
void | setUseDesignMetrics (bool b ) |
构造空的 QTextDocument 采用给定 parent .
构造 QTextDocument containing the plain (unformatted) text specified, and with the given parent .
销毁文档。
Adds the resource 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\" />");
把文档调节到合理大小。
该函数在 Qt 4.2 引入。
另请参阅 idealWidth (), textWidth ,和 size .
Returns a vector of text formats for all the formats used in the document.
返回可用的重做步骤数。
该函数在 Qt 4.6 引入。
另请参阅 isRedoAvailable ().
返回可用的撤消步骤数。
该函数在 Qt 4.6 引入。
另请参阅 isUndoAvailable ().
返回文档的第一文本块。
另请参阅 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.
该函数在 Qt 4.3 引入。
返回字符位于位置 pos ,或 null 字符若位置超出范围。
该函数在 Qt 4.5 引入。
另请参阅 characterCount ().
返回此文档的字符数。
该函数在 Qt 4.5 引入。
另请参阅 blockCount () 和 characterAt ().
[virtual]
void
QTextDocument::
clear
()
清理文档。
清零堆栈,指定通过 stacksToClear .
此方法清零撤消堆栈、重做堆栈或两者 (默认) 中的所有命令。若命令被清零,适当信号被发射, QTextDocument::undoAvailable () 或 QTextDocument::redoAvailable ().
该函数在 Qt 4.7 引入。
另请参阅 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
)
This signal is emitted whenever the document's content changes; for example, when text is inserted or deleted, or when formatting is applied.
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
()
This signal is emitted whenever the document's content changes; for example, when text is inserted or deleted, or when formatting is applied.
另请参阅 contentsChange ().
[virtual protected]
QTextObject
*QTextDocument::
createObject
(const
QTextFormat
&
format
)
Creates and returns a new document object (a QTextObject ), based on the given 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() 信号在 QTextEdit .
The default cursor movement style is used by all QTextCursor objects created from the document. The default is Qt::LogicalMoveStyle .
该函数在 Qt 4.8 引入。
另请参阅 setDefaultCursorMoveStyle ().
Returns the default font to be used in the document layout.
注意: Getter 函数对于特性 defaultFont .
另请参阅 setDefaultFont ().
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.
该函数在 Qt 4.3 引入。
注意: Getter 函数对于特性 defaultTextOption .
另请参阅 setDefaultTextOption ().
返回此文档的文档布局。
另请参阅 setDocumentLayout ().
[signal]
void
QTextDocument::
documentLayoutChanged
()
This signal is emitted when a new document layout is set.
该函数在 Qt 4.4 引入。
另请参阅 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.
该函数在 Qt 4.2 引入。
此函数返回当遍历时,测试文档结尾的块。
for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next()) cout << it.text().toStdString() << endl;
返回的块无效,表示文档最后块之后的块。可以使用 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.
Returns a cursor with the match selected if 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-sensitive, 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.
Returns a cursor with the match selected if 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. The FindCaseSensitively 选项被忽略对于此重载,使用 QRegExp::caseSensitivity 代替。
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 from cursor , and proceeds forwards through the document unless specified otherwise in the search options. The options control the type of search performed. The FindCaseSensitively 选项被忽略对于此重载,使用 QRegExp::caseSensitivity 代替。
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-sensitive, and can match text anywhere in the document.
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.
该函数在 Qt 5.5 引入。
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-sensitive, and can match text anywhere in the document.
该函数在 Qt 5.5 引入。
返回文本块包含 pos 的字符。
返回文本块包含指定 lineNumber .
该函数在 Qt 4.5 引入。
另请参阅 QTextBlock::firstLineNumber ().
返回文本块采用指定 blockNumber .
该函数在 Qt 4.4 引入。
另请参阅 QTextBlock::blockNumber ().
返回文档的第一文本块。
该函数在 Qt 4.4 引入。
Returns the ideal width of the text document. The ideal width is the actually used width of the document without optional alignments taken into account. It is always <= size ().width().
该函数在 Qt 4.2 引入。
另请参阅 adjustSize () 和 textWidth .
返回
true
若文档为空;否则返回
false
.
返回
true
若重做是可用的;否则返回
false
.
另请参阅 isUndoAvailable () 和 availableRedoSteps ().
返回
true
若撤消可用;否则返回
false
.
另请参阅 isRedoAvailable () 和 availableUndoSteps ().
返回文档的最后 (有效) 文本块。
该函数在 Qt 4.4 引入。
Returns the number of lines of this document (if the layout supports this). Otherwise, this is identical to the number of blocks.
该函数在 Qt 4.5 引入。
另请参阅 blockCount () 和 characterCount ().
[virtual protected]
QVariant
QTextDocument::
loadResource
(
int
type
, const
QUrl
&
name
)
Loads data of the specified type from the resource with the given 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.
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) 在文档,然后插入文本导致发射信号。若撤消该操作,导致文档返回其原始未修改状态,将再次发射信号。
Returns the text object associated with the given objectIndex .
返回文本对象关联格式 f .
返回此文档中的页数。
Prints the document to the given printer . The QPageablePaintDevice 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.
该函数在 Qt 4.2 引入。
[slot]
void
QTextDocument::
redo
()
这是重载函数。
Redoes the last editing operation on the document if 重做是可用的 .
[signal]
void
QTextDocument::
redoAvailable
(
bool
available
)
This signal is emitted whenever redo operations become available ( available is true) or unavailable ( available is false).
Returns data of the specified type from the resource with the given 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.
另请参阅 QTextDocument::ResourceType .
Returns the document's revision (if undo is enabled).
The revision is guaranteed to increase when a document that is not modified is edited.
该函数在 Qt 4.4 引入。
另请参阅 QTextBlock::revision () 和 isModified ().
Returns the document's root frame.
Sets the default cursor movement style to the given style .
该函数在 Qt 4.8 引入。
另请参阅 defaultCursorMoveStyle ().
Sets the default font to use in the document layout.
注意: Setter 函数对于特性 defaultFont .
另请参阅 defaultFont ().
将默认文本选项设为 option .
该函数在 Qt 4.3 引入。
注意: 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".
注意: 调用者有责任确保正确解码文本当 QString 包含的 HTML 被创建并传递给 setHtml() 时。
另请参阅 setPlainText () 和 支持的 HTML 子集 .
设置 width 用于文本列表和文本块缩进。
The indent properties of QTextListFormat and QTextBlockFormat specify multiples of this value. The default indent width is 40 .
该函数在 Qt 4.4 引入。
注意: Setter 函数对于特性 indentWidth .
另请参阅 indentWidth ().
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 ().
Returns a string containing an HTML representation of the document.
encoding parameter specifies the value for the charset attribute in the html header. For example if 'utf-8' is specified then the beginning of the generated html will look like this:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body>...
If no encoding is specified then no such meta information is generated.
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 specify the encoding you're going to use for the conversion to a byte array here.
另请参阅 支持的 HTML 子集 .
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 代替。
该函数在 Qt 5.9 引入。
另请参阅 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 文档编制了解细节。
该函数在 Qt 4.2 引入。
另请参阅 undoAvailable () 和 isUndoRedoEnabled ().
[slot]
void
QTextDocument::
undo
()
这是重载函数。
[signal]
void
QTextDocument::
undoAvailable
(
bool
available
)
This signal is emitted whenever undo operations become available ( available is true) or unavailable ( available is 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 .
该函数在 Qt 4.4 引入。