QTextBlock 类

QTextBlock class provides a container for text fragments in a QTextDocument . 更多...

头: #include <QTextBlock>
qmake: QT += gui

注意: 此类的所有函数 可重入 .

公共类型

class iterator
typedef Iterator

公共函数

QTextBlock (const QTextBlock & other )
iterator begin () const
QTextBlockFormat blockFormat () const
int blockFormatIndex () const
int blockNumber () const
QTextCharFormat charFormat () const
int charFormatIndex () const
void clearLayout ()
bool contains (int position ) const
const QTextDocument * document () const
iterator end () const
int firstLineNumber () const
bool isValid () const
bool isVisible () const
QTextLayout * layout () const
int length () const
int lineCount () const
QTextBlock next () const
int position () const
QTextBlock 上一 () const
int revision () const
void setLineCount (int count )
void setRevision (int rev )
void setUserData (QTextBlockUserData * data )
void setUserState (int state )
void setVisible (bool visible )
QString text () const
Qt::LayoutDirection textDirection () const
QVector<QTextLayout::FormatRange> textFormats () const
QTextList * textList () const
QTextBlockUserData * userData () const
int userState () const
bool operator!= (const QTextBlock & other ) const
bool operator< (const QTextBlock & other ) const
QTextBlock & operator= (const QTextBlock & other )
bool operator== (const QTextBlock & other ) const

详细描述

QTextBlock class provides a container for text fragments in a QTextDocument .

文本块将块或文本段落封装在 QTextDocument . QTextBlock provides read-only access to the block/paragraph structure of QTextDocuments. It is mainly of use if you want to implement your own layouts for the visual representation of a QTextDocument , or if you want to iterate over a document and write out the contents in your own custom format.

Text blocks are created by their parent documents. If you need to create a new text block, or modify the contents of a document while examining its contents, use the cursor-based interface provided by QTextCursor 代替。

各文本块位于特定 position () 在 document (). The contents of the block can be obtained by using the text () 函数。 length () function determines the block's size within the document (including formatting characters). The visual properties of the block are determined by its text layout (), its charFormat (), and its blockFormat ().

next () 和 上一 () functions enable iteration over consecutive valid blocks in a document under the condition that the document is not modified by other means during the iteration process. Note that, although blocks are returned in sequence, adjacent blocks may come from different places in the document structure. The validity of a block can be determined by calling isValid ().

QTextBlock provides comparison operators to make it easier to work with blocks: operator== () 比较 2 块是否相等, operator!= () compares two blocks for inequality, and operator< () determines whether a block precedes another in the same document.

另请参阅 QTextBlockFormat , QTextCharFormat ,和 QTextFragment .

成员类型文档编制

typedef QTextBlock:: Iterator

Qt 样式同义词 QTextBlock::iterator .

成员函数文档编制

QTextBlock:: QTextBlock (const QTextBlock & other )

拷贝 other 文本块的属性到此文本块。

iterator QTextBlock:: begin () const

Returns a text block iterator pointing to the beginning of the text block.

另请参阅 end ().

QTextBlockFormat QTextBlock:: blockFormat () const

返回 QTextBlockFormat that describes block-specific properties.

另请参阅 charFormat ().

int QTextBlock:: blockFormatIndex () const

Returns an index into the document's internal list of block formats for the text block's format.

另请参阅 QTextDocument::allFormats ().

int QTextBlock:: blockNumber () const

返回此块的编号,或 -1 若块无效。

该函数在 Qt 4.4 引入。

另请参阅 QTextCursor::blockNumber ().

QTextCharFormat QTextBlock:: charFormat () const

返回 QTextCharFormat that describes the block's character format. The block's character format is used when inserting text into an empty block.

另请参阅 blockFormat ().

int QTextBlock:: charFormatIndex () const

Returns an index into the document's internal list of character formats for the text block's character format.

另请参阅 QTextDocument::allFormats ().

void QTextBlock:: clearLayout ()

清零 QTextLayout 用于布置并显示块内容。

该函数在 Qt 4.4 引入。

另请参阅 layout ().

bool QTextBlock:: contains ( int position ) const

返回 true 若给定 position 位于文本块内;否则返回 false .

const QTextDocument *QTextBlock:: document () const

Returns the text document this text block belongs to, or 0 if the text block does not belong to any document.

iterator QTextBlock:: end () const

返回指向文本块末尾的文本块迭代器。

另请参阅 begin (), next (),和 上一 ().

int QTextBlock:: firstLineNumber () const

Returns the first line number of this block, or -1 if the block is invalid. Unless the layout supports it, the line number is identical to the block number.

该函数在 Qt 4.5 引入。

另请参阅 QTextBlock::blockNumber ().

bool QTextBlock:: isValid () const

返回 true 若此文本块有效;否则返回 false .

bool QTextBlock:: isVisible () const

返回 true 若块可见;否则返回 false .

该函数在 Qt 4.4 引入。

另请参阅 setVisible ().

QTextLayout *QTextBlock:: layout () const

返回 QTextLayout 用于布置并显示块内容。

注意:返回的 QTextLayout object can only be modified from the documentChanged implementation of a QAbstractTextDocumentLayout subclass. Any changes applied from the outside cause undefined behavior.

另请参阅 clearLayout ().

int QTextBlock:: length () const

返回块的长度 (以字符为单位)。

注意: The length returned includes all formatting characters, for example, newline.

另请参阅 text (), charFormat (),和 blockFormat ().

int QTextBlock:: lineCount () const

Returns the line count. Not all document layouts support this feature.

该函数在 Qt 4.5 引入。

另请参阅 setLineCount ().

QTextBlock QTextBlock:: next () const

返回此块之后的文档文本块;或空文本块若这是最后一个。

注意:下一个块可能与此块位于不同的框架 (或表格) 中。

另请参阅 上一 (), begin (),和 end ().

int QTextBlock:: position () const

返回文档块首字符的索引。

QTextBlock QTextBlock:: 上一 () const

Returns the text block in the document before this block, or an empty text block if this is the first one.

Note that the previous block may be in a different frame or table to this block.

另请参阅 next (), begin (),和 end ().

int QTextBlock:: revision () const

返回块修订。

该函数在 Qt 4.4 引入。

另请参阅 setRevision () 和 QTextDocument::revision ().

void QTextBlock:: setLineCount ( int count )

把行数设为 count .

该函数在 Qt 4.5 引入。

另请参阅 lineCount ().

void QTextBlock:: setRevision ( int rev )

把块修订设为 rev .

该函数在 Qt 4.4 引入。

另请参阅 revision () 和 QTextDocument::revision ().

void QTextBlock:: setUserData ( QTextBlockUserData * data )

附加给定 data 对象到文本块。

QTextBlockUserData can be used to store custom settings. The ownership is passed to the underlying text document, i.e. the provided QTextBlockUserData object will be deleted if the corresponding text block gets deleted. The user data object is not stored in the undo history, so it will not be available after undoing the deletion of a text block.

For example, if you write a programming editor in an IDE, you may want to let your user set breakpoints visually in your code for an integrated debugger. In a programming editor a line of text usually corresponds to one QTextBlock QTextBlockUserData interface allows the developer to store data for each QTextBlock , like for example in which lines of the source code the user has a breakpoint set. Of course this could also be stored externally, but by storing it inside the QTextDocument , it will for example be automatically deleted when the user deletes the associated line. It's really just a way to store custom information in the QTextDocument without using custom properties in QTextFormat which would affect the undo/redo stack.

该函数在 Qt 4.1 引入。

另请参阅 userData ().

void QTextBlock:: setUserState ( int state )

存储指定 state integer value in the text block. This may be useful for example in a syntax highlighter to store a text parsing state.

该函数在 Qt 4.1 引入。

另请参阅 userState ().

void QTextBlock:: setVisible ( bool visible )

把块的可见性设为 visible .

该函数在 Qt 4.4 引入。

另请参阅 isVisible ().

QString QTextBlock:: text () const

以纯文本形式返回块内容。

另请参阅 length (), charFormat (),和 blockFormat ().

Qt::LayoutDirection QTextBlock:: textDirection () const

返回解析文本方向。

If the block has no explicit direction set, it will resolve the direction from the blocks content. Returns either Qt::LeftToRight or Qt::RightToLeft .

该函数在 Qt 4.7 引入。

另请参阅 QTextFormat::layoutDirection (), QString::isRightToLeft (),和 Qt::LayoutDirection .

QVector < QTextLayout::FormatRange > QTextBlock:: textFormats () const

Returns the block's text format options as a list of continuous ranges of QTextCharFormat . The range's character format is used when inserting text within the range boundaries.

该函数在 Qt 5.3 引入。

另请参阅 charFormat () 和 blockFormat ().

QTextList *QTextBlock:: textList () const

If the block represents a list item, returns the list that the item belongs to; otherwise returns 0.

QTextBlockUserData *QTextBlock:: userData () const

返回指针指向 QTextBlockUserData object if previously set with setUserData () or a null pointer.

该函数在 Qt 4.1 引入。

另请参阅 setUserData ().

int QTextBlock:: userState () const

返回先前设置的整数值采用 setUserState () 或 -1。

该函数在 Qt 4.1 引入。

另请参阅 setUserState ().

bool QTextBlock:: operator!= (const QTextBlock & other ) const

返回 true 若此文本块不同于 other 文本块。

bool QTextBlock:: operator< (const QTextBlock & other ) const

返回 true 若此文本块的发生前于 other 文本块在文档中。

QTextBlock &QTextBlock:: operator= (const QTextBlock & other )

赋值 other 文本块到此文本块。

bool QTextBlock:: operator== (const QTextBlock & other ) const

返回 true 若此文本块相同如 other 文本块。