Qt 4.0: QTextBlock Class Reference

|  | Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |

# QTextBlock Class Reference
[QtGui module]

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

    #include <QTextBlock>

- List of all members, including inherited members

### Public Types

- class iterator
- typedef Iterator

### Public Functions

- QTextBlock ( const QTextBlock & other )
- iterator begin () const
- QTextBlockFormat blockFormat () const
- int blockFormatIndex () const
- QTextCharFormat charFormat () const
- int charFormatIndex () const
- bool contains ( int position ) const
- const QTextDocument * document () const
- iterator end () const
- bool isValid () const
- QTextLayout * layout () const
- int length () const
- QTextBlock next () const
- int position () const
- QTextBlock previous () const
- QString text () const
- QTextList * textList () const
- bool operator!= ( const QTextBlock & other ) const
- bool operator< ( const QTextBlock & other ) const
- QTextBlock & operator= ( const QTextBlock & other )
- bool operator== ( const QTextBlock & other ) const

## 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, use the cursor-based interface provided by QTextCursor.

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 allow navigation between blocks within the document. Note that blocks are returned in sequence, so adjacent blocks may come from different places in the document structure.

QTextBlock provides comparison operators two 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.

## Member Type Documentation

### typedef QTextBlock::Iterator

Qt-style synonym for QTextBlock::iterator.

## Member Function Documentation

### QTextBlock::QTextBlock ( const QTextBlock & other )

Copies the other text block's attributes to this text block.

### iterator QTextBlock::begin () const

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

See also end().

### QTextBlockFormat QTextBlock::blockFormat () const

Returns the QTextBlockFormat that describes block-specific properties.

See also charFormat().

### int QTextBlock::blockFormatIndex () const

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

See also QTextDocument::object().

### QTextCharFormat QTextBlock::charFormat () const

Returns the QTextCharFormat that describes the block's character format. This is mainly used to draw block-specific additions such as e.g. list markers.

See also blockFormat().

### int QTextBlock::charFormatIndex () const

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

See also QTextDocument::object().

### bool QTextBlock::contains ( int position ) const

Returns true if the given position is located within the text block; otherwise returns 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

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

See also begin(), next(), and previous().

### bool QTextBlock::isValid () const

Returns true if this text block is valid; otherwise returns false.

### QTextLayout * QTextBlock::layout () const

Returns the QTextLayout that is used to lay out and display the block's contents.

### int QTextBlock::length () const

Returns the length of the block in characters.

See also text(), charFormat(), and blockFormat().

### QTextBlock QTextBlock::next () const

Returns the text block in the document after this block, or an empty text block if this is the last one.

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

See also previous(), begin(), and end().

### int QTextBlock::position () const

Returns the starting position of the block within the document.

### QTextBlock QTextBlock::previous () 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 next block may be in a different frame or table to this block.

See also next(), begin(), and end().

### QString QTextBlock::text () const

Returns the block's contents as plain text.

See also length(), charFormat(), and blockFormat().

### QTextList * QTextBlock::textList () const

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

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

Returns true if this text block is different from the other text block.

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

Returns true if this text block occurs before the other text block in the document.

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

Assigns the other text block to this text block.

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

Returns true if this text block is the same as the other text block.