|  | Home · Overviews · Examples

# QTextBlock Class Reference
[com.trolltech.qt.gui module]

The `QTextBlock` class provides a container for text fragments in a `QTextDocument`. More...

## Detailed Description

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

A text block encapsulates a block or paragraph of text in a `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` instead.

Each text block is located at a specific `position` in a `document`. The contents of the block can be obtained by using the `text` function. The `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`.

The `next` and `previous` 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==` compares two block for equality, `operator!=` compares two blocks for inequality, and `operator<` determines whether a block precedes another in the same document.

See also `QTextBlockFormat`, `QTextCharFormat`, and `QTextFragment`.