The QTextDocument 類保持格式化文本。 更多...
| 頭: | #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 = nullptr) | |
| QTextDocument (const QString & text , QObject * parent = nullptr) | |
| virtual | ~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 (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 QRegExp & expr , int from = 0, QTextDocument::FindFlags options = FindFlags()) const |
| QTextCursor | find (const QRegExp & expr , const QTextCursor & cursor , 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 | 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 |
| 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 (QTextDocument::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 () |
| const QMetaObject | staticMetaObject |
| virtual QTextObject * | createObject (const QTextFormat & format ) |
| virtual QVariant | loadResource (int type , const QUrl & name ) |
The QTextDocument 類保持格式化文本。
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 (或獨立使用)。
描述各文檔元素是通過關聯格式對象。QTextDocument 把各格式對象視為唯一對象,且可以傳遞給 objectForFormat () 以獲得應用它的文檔元素。
A QTextDocument can be edited programmatically using a QTextCursor ,且可以通過遍曆文檔結構審查其內容。按 root (根) 框架下文檔元素層次結構存儲整個文檔結構,查找采用 rootFrame () 函數。另外,若僅僅想要遍曆文檔的正文內容,可以使用 begin (), end (),和 findBlock () 來檢索可以審查和遍曆的文本塊。
文檔布局的確定是通過 documentLayout ();可以創建自己的 QAbstractTextDocumentLayout 子類並設置它使用 setDocumentLayout () 若想要使用自己的布局邏輯。可以獲得文檔的標題及其它元信息通過調用 metaInformation () 函數。嚮用戶暴露文檔是透過 QTextEdit 類,文檔標題也是可用的憑藉 QTextEdit::documentTitle () 函數。
The toPlainText () 和 toHtml () 方便函數允許以純文本和 HTML (超文本標記語言) 方式檢索文檔內容。文檔文本的搜索可以使用 find () 函數。
控製文檔履行撤消/重做操作可以使用 setUndoRedoEnabled () 函數。編輯器 Widget 控製撤銷/重做係統可以透過 undo () 和 redo () 槽;文檔還提供 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 用作基,當加載相關資源時。 |
另請參閱 metaInformation () 和 setMetaInformation ().
此枚舉描述可以加載的資源類型通過 QTextDocument 's loadResource () 函數。
| 常量 | 值 | 描述 |
|---|---|---|
QTextDocument::HtmlResource
|
1
|
資源包含 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
|
資源包含 CSS。 |
QTextDocument::UserResource
|
100
|
用戶定義資源類型的第 1 可用值。 |
另請參閱 loadResource ().
| 常量 | 值 | 描述 |
|---|---|---|
QTextDocument::UndoStack
|
0x01
|
撤消堆棧。 |
QTextDocument::RedoStack
|
0x02
|
重做堆棧。 |
QTextDocument::UndoAndRedoStacks
|
UndoStack | RedoStack
|
撤消和重做堆棧。 |
此特性保持用於解析文檔中相對資源 URL (統一資源定位符) 的基 URL。
把資源 URL 解析成基於 URL 在同一目錄下的目標,這意味著將忽略最後一個 / 之後路徑的任何部分。
| 基 URL | 相對 URL | 解析 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 子集 .
此特性保持的默認文本選項,將設置到所有 QTextLayout 在文檔中。
當 QTextBlock 被創建,defaultTextOption 將設置到其 QTextLayout 。這允許為文檔設置全局特性 (譬如:默認換行模式)。
訪問函數:
| QTextOption | defaultTextOption () const |
| void | setDefaultTextOption (const QTextOption & option ) |
圍繞文檔的邊距。默認為 4。
該特性在 Qt 4.5 引入。
訪問函數:
| qreal | documentMargin () const |
| void | setDocumentMargin (qreal margin ) |
返迴用於文本列錶和文本塊縮進的寬度。
縮進特性對於 QTextListFormat and QTextBlockFormat 指定此值的倍數。默認縮進寬度為 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 ().
此特性保持應該用於布置文檔的頁麵大小
單位由底層描繪設備確定。大小以邏輯像素為單位度量當描繪到屏幕時,並按點 (1/72 英寸) 當描繪到打印機。
默認情況下,對於新近創建的空文檔,此特性包含未定義大小。
訪問函數:
| QSizeF | pageSize () const |
| void | setPageSize (const QSizeF & size ) |
另請參閱 modificationChanged ().
Returns the actual size of the document. This is equivalent to documentLayout ()->documentSize();
文檔的大小可以改變,通過設置文本寬度,或設置整個頁麵的大小。
注意,寬度始終 > = pageSize ().width().
默認情況下,對於新近創建的空文檔,此特性包含配置從屬大小。
該特性在 Qt 4.2 引入。
訪問函數:
| QSizeF | size () const |
另請參閱 setTextWidth (), setPageSize (),和 idealWidth ().
文本寬度指定文檔中文本的首選寬度。若文本 (或一般內容) 比指定寬,會將其分解成多行並垂直增長。若無法把文本分解成多行以擬閤進指定文本寬度,文本將更大且 size () 和 idealWidth () 特性會反映這。
若文本寬度被設為 -1,那麼將不會把文本分解成多行,除非透過明確換行 (或新建段落) 實施。
默認值為 -1。
設置文本寬度還會將頁麵高度設為 -1,導緻文檔以連續方式垂直增長 (或收縮)。若想要文檔布局將文本分解成多頁,那麼必須設置 pageSize 特性代替。
該特性在 Qt 4.2 引入。
訪問函數:
| qreal | textWidth () const |
| void | setTextWidth (qreal width ) |
另請參閱 size (), idealWidth (),和 pageSize ().
此特性保持此文檔啓是否啓用撤銷/重做
這默認為 true。若禁用,清零撤消堆棧,且不會嚮它添加項。
訪問函數:
| bool | isUndoRedoEnabled () const |
| void | setUndoRedoEnabled (bool enable ) |
此特性保持文檔是否使用設計字體規格,來改進文本布局的精度
若此特性被設為 true,布局將使用設計規格。否則,描繪設備設置的規格在 QAbstractTextDocumentLayout::setPaintDevice () 會被使用。
使用設計規格使布局擁有的寬度,不再依賴提示和像素捨入。這意味著 WYSIWYG (所見即所得) 文本布局變為可能,因為寬度基於 paintdevice 規格比其它能更綫性比例縮放。
默認情況下,此特性為
false
.
該特性在 Qt 4.1 引入。
訪問函數:
| bool | useDesignMetrics () const |
| void | setUseDesignMetrics (bool b ) |
構造空的 QTextDocument 采用給定 parent .
構造 QTextDocument containing the plain (unformatted) text 指定,和采用給定 parent .
[虛擬]
QTextDocument::
~QTextDocument
()
銷毀文檔。
添加資源 resource 到資源緩存,使用 type and name 作為標識符。 type 值應該來自 QTextDocument::ResourceType .
例如,可以把圖像添加作為資源,為從文檔內引用它:
document->addResource(QTextDocument::ImageResource,
QUrl("mydata://image.png"), QVariant(image));
可以把圖像插入文檔使用 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
)
此信號發射,當文檔中的文本塊總數變化時。值被傳入 newBlockCount 是新的總計。
該函數在 Qt 4.3 引入。
返迴字符位於位置 pos ,或 null 字符若位置超齣範圍。
該函數在 Qt 4.5 引入。
另請參閱 characterCount ().
返迴此文檔的字符數。
該函數在 Qt 4.5 引入。
另請參閱 blockCount () 和 characterAt ().
[虛擬]
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
)
此信號被發射每當文檔內容改變時;例如,當插入 (或刪除) 文本 (或應用格式) 時。
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() 信號在 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 ().
返迴用於文檔布局的默認字體。
注意: getter 函數對於特性 defaultFont .
另請參閱 setDefaultFont ().
默認文本選項可以用於所有 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
()
此信號被發射,當設置新文檔布局時。
該函數在 Qt 4.4 引入。
另請參閱 setDocumentLayout ().
繪製文檔內容采用描繪器 p ,裁剪到 rect 。若 rect 是 null 矩形 (默認) 則不裁剪描繪文檔。
該函數在 Qt 4.2 引入。
此函數返迴當遍曆時,測試文檔結尾的塊。
for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next())
cout << it.text().toStdString() << endl;
返迴的塊無效,錶示文檔最後塊之後的塊。可以使用 lastBlock () 以檢索文檔的最後有效塊。
另請參閱 lastBlock ().
查找下一齣現為字符串 subString 在文檔中。搜索始於位置給定 cursor ,且透過文檔嚮前繼續進行,除非有指定,否則按 options 進行搜索。 options 控製履行搜索的類型。
返迴具有匹配選中的光標若 subString 被找到;否則返迴 null 光標。
若給定 cursor 擁有選定,在選定後開始搜索;否則從光標位置開始。
默認情況下,搜索不區分大小寫,且可以匹配文檔中任何地方的文本。
這是重載函數。
查找下一齣現為字符串 subString 在文檔中。搜索始於給定 position ,且透過文檔嚮前繼續進行,除非有指定,否則按 options 進行搜索。 options 控製履行搜索的類型。
返迴具有匹配選中的光標若 subString 被找到;否則返迴 null 光標。
若 position 為 0 (默認) 搜索從文檔開頭開始;否則從指定位置開始。
這是重載函數。
查找的下一齣現匹配給定正則錶達式 expr ,在文檔同一段落中。
搜索始於給定 from 位置,並透過文檔嚮前繼續進行,除非有指定,否則按 options 進行搜索。 options 控製履行搜索的類型。 FindCaseSensitively 選項被忽略對於此重載,使用 QRegExp::caseSensitivity 代替。
返迴具有匹配選中的光標,若找到匹配;否則返迴 null 光標。
若 from 位置為 0 (默認),搜索從文檔開頭開始;否則,從指定位置開始。
這是重載函數。
查找的下一齣現匹配給定正則錶達式 expr ,在文檔同一段落中。
搜索始於位置給定 cursor ,且透過文檔嚮前繼續進行,除非有指定,否則按 options 進行搜索。 options 控製履行搜索的類型。 FindCaseSensitively 選項被忽略對於此重載,使用 QRegExp::caseSensitivity 代替。
返迴具有匹配選中的光標,若找到匹配;否則返迴 null 光標。
若給定 cursor 擁有選定,在選定後開始搜索;否則從光標位置開始。
默認情況下,搜索不區分大小寫,且可以匹配文檔中任何地方的文本。
查找的下一齣現匹配給定正則錶達式 expr ,在文檔同一段落中。
搜索始於給定 from 位置,並透過文檔嚮前繼續進行,除非有指定,否則按 options 進行搜索。 options 控製履行搜索的類型。
返迴具有匹配選中的光標,若找到匹配;否則返迴 null 光標。
若 from 位置為 0 (默認),搜索從文檔開頭開始;否則,從指定位置開始。
該函數在 Qt 5.5 引入。
查找的下一齣現匹配給定正則錶達式 expr ,在文檔同一段落中。
搜索始於位置給定 cursor ,且透過文檔嚮前繼續進行,除非有指定,否則按 options 進行搜索。 options 控製履行搜索的類型。
返迴具有匹配選中的光標,若找到匹配;否則返迴 null 光標。
若給定 cursor 擁有選定,在選定後開始搜索;否則從光標位置開始。
默認情況下,搜索不區分大小寫,且可以匹配文檔中任何地方的文本。
該函數在 Qt 5.5 引入。
返迴文本塊包含 pos 的字符。
返迴文本塊包含指定 lineNumber .
該函數在 Qt 4.5 引入。
另請參閱 QTextBlock::firstLineNumber ().
返迴文本塊采用指定 blockNumber .
該函數在 Qt 4.4 引入。
另請參閱 QTextBlock::blockNumber ().
返迴文檔的第一文本塊。
該函數在 Qt 4.4 引入。
返迴文本文檔的理想寬度。理想寬度是不考慮可選對齊的文檔實際使用寬度。它終 <= size ().width().
該函數在 Qt 4.2 引入。
另請參閱 adjustSize () 和 textWidth .
返迴
true
若文檔為空;否則返迴
false
.
返迴
true
若重做是可用的;否則返迴
false
.
另請參閱 isUndoAvailable () 和 availableRedoSteps ().
返迴
true
若撤消可用;否則返迴
false
.
另請參閱 isRedoAvailable () 和 availableUndoSteps ().
返迴文檔的最後 (有效) 文本塊。
該函數在 Qt 4.4 引入。
返迴此文檔的行數 (若布局支持此)。否則,這就等同於塊數。
該函數在 Qt 4.5 引入。
另請參閱 blockCount () 和 characterCount ().
[virtual protected]
QVariant
QTextDocument::
loadResource
(
int
type
, const
QUrl
&
name
)
加載數據按指定 type 從資源采用給定 name .
此函數的調用是由富文本引擎,以請求未直接存儲的數據通過 QTextDocument ,但仍然與之關聯。例如,圖像的間接引用是通過 name 屬性 QTextImageFormat 對象。
當被 Qt 調用時, type 是之一值的 QTextDocument::ResourceType .
若 QTextDocument 是子級對象對於 QObject 擁有可援引 loadResource 方法譬如 QTextEdit , QTextBrowser 或 QTextDocument 本身,那麼,默認實現會試著從父級檢索數據。
注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .
標記內容指定通過給定 position and length 為 dirty (髒),告知文檔需要再次布局。
返迴文檔類型的有關元信息指定通過 info .
另請參閱 setMetaInformation ().
[signal]
void
QTextDocument::
modificationChanged
(
bool
changed
)
此信號被發射每當文檔的內容以影響修改狀態的方式更改時。若 changed 為 true,文檔已被修改;否則為 false。
例如:調用 setModified (false) 在文檔,然後插入文本導緻發射信號。若撤消該操作,導緻文檔返迴其原始未修改狀態,將再次發射信號。
返迴的文本對象關聯給定 objectIndex .
返迴文本對象關聯格式 f .
返迴此文檔中的頁數。
將文檔打印到給定 printer 。 QPagedPaintDevice 必須設置,先於與此函數一起使用。
這是將整個文檔,打印到打印機的僅方便方法。
若文檔已透過指定高度被分頁按 pageSize () 特性,按原樣打印。
若文檔未分頁,例如,像文檔用於 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 ().
重做文檔的最後編輯操作若 重做是可用的 .
提供的 cursor 位於重做編輯操作位置的末尾。
該函數在 Qt 4.2 引入。
[slot]
void
QTextDocument::
redo
()
這是重載函數。
重做文檔的最後編輯操作若 重做是可用的 .
[signal]
void
QTextDocument::
redoAvailable
(
bool
available
)
此信號被發射,每當重做操作變為可用時 ( available 為 True) 或不可用 ( available 為 false)。
返迴數據為指定 type 從資源采用給定 name .
此函數的調用是由富文本引擎,以請求未直接存儲的數據通過 QTextDocument ,但仍然與之關聯。例如,圖像的間接引用是通過 name 屬性 QTextImageFormat 對象。
資源緩存在文檔內部。若在緩存中找不到資源, loadResource 被調用以試著加載資源。 loadResource 則應使用 addResource 以將資源添加到緩存。
另請參閱 QTextDocument::ResourceType .
返迴文檔的修訂 (若撤消被啓用)。
保證遞增修訂,當編輯未修改文檔時。
該函數在 Qt 4.4 引入。
另請參閱 QTextBlock::revision () 和 isModified ().
返迴文檔的根框架。
把默認光標移動樣式設為給定 style .
該函數在 Qt 4.8 引入。
另請參閱 defaultCursorMoveStyle ().
設置默認 font 以用於文檔布局。
注意: setter 函數對於特性 defaultFont .
另請參閱 defaultFont ().
將默認文本選項設為 option .
該函數在 Qt 4.3 引入。
注意: setter 函數對於特性 defaultTextOption .
另請參閱 defaultTextOption ().
將文檔設為使用給定 layout 。刪除先前布局。
另請參閱 documentLayoutChanged ().
替換文檔的整個內容以給定 HTML 格式化文本按 html 字符串。撤消/重做曆史被重置,當調用此函數時。
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 用於文本列錶和文本塊縮進。
縮進特性對於 QTextListFormat and QTextBlockFormat 指定此值的倍數。默認縮進寬度為 40。
該函數在 Qt 4.4 引入。
注意: setter 函數對於特性 indentWidth .
另請參閱 indentWidth ().
設置文檔的元信息,類型指定通過 info 到給定 string .
另請參閱 metaInformation ().
替換文檔的整個內容采用給定純 text 。撤消/重做曆史被重置,當調用此函數時。
另請參閱 setHtml ().
返迴包含文檔 HTML 錶示的字符串。
The 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 子集 .
返迴文檔包含的純文本。若想要格式化信息,使用 QTextCursor 代替。
此函數返迴如同 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 ().
返迴文檔包含的原生文本,沒有任何格式化信息。若想要格式化信息,使用 QTextCursor 代替。
該函數在 Qt 5.9 引入。
另請參閱 toPlainText ().
撤消文檔的最後編輯操作,若撤銷可用。提供 cursor 位於撤消編輯操作位置的末尾。
見 Qt 撤消框架 文檔編製瞭解細節。
該函數在 Qt 4.2 引入。
另請參閱 undoAvailable () 和 isUndoRedoEnabled ().
[slot]
void
QTextDocument::
undo
()
這是重載函數。
[signal]
void
QTextDocument::
undoAvailable
(
bool
available
)
此信號被發射每當撤消操作變為可用 ( available 為 True) 或不可用 ( available 為 false)。
見 Qt 撤消框架 文檔編製瞭解細節。
另請參閱 undo () 和 isUndoRedoEnabled ().
[signal]
void
QTextDocument::
undoCommandAdded
()
此信號發射,每當把新撤銷級彆添加到 QTextDocument .
該函數在 Qt 4.4 引入。