Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QTextBlockFormat Class Reference

The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument. More...

    #include <QTextBlockFormat>

Inherits QTextFormat.

- List of all members, including inherited members

### Public Types

- enum Direction { LeftToRight, RightToLeft, AutoDirection }

### Public Functions

- QTextBlockFormat ()
- Qt::Alignment alignment () const
- QColor backgroundColor () const
- int bottomMargin () const
- void clearBackgroundColor ()
- Direction direction () const
- int firstLineMargin () const
- int indent () const
- bool isValid () const
- int leftMargin () const
- bool nonBreakableLines () const
- int rightMargin () const
- void setAlignment ( Qt::Alignment alignment )
- void setBackgroundColor ( const QColor & color )
- void setBottomMargin ( int margin )
- void setDirection ( Direction direction )
- void setFirstLineMargin ( int margin )
- void setIndent ( int indentation )
- void setLeftMargin ( int margin )
- void setNonBreakableLines ( bool b )
- void setRightMargin ( int margin )
- void setTopMargin ( int margin )
- int topMargin () const

- 45 public functions inherited from QTextFormat

## Detailed Description

The QTextBlockFormat class provides formatting information for blocks of text in a QTextDocument.

A document is composed of a list of blocks. Each block can contain an item of some kind, for example, a paragraph of text, a table, a list, or an image. Every block has an associated QTextBlockFormat that specifies its characteristics.

To cater for left-to-right and right-to-left languages you can set a block's direction with setDirection(). Paragraph alignment is set with setAlignment(). Margins are controlled by setTopMargin(), setBottomMargin(), setLeftMargin(), setRightMargin(), and setFirstLineMargin(). Overall indentation is set with setIndent(). Line breaking is controlled with setNonBreakableLines(). The paragraph's background color is set with setBackgroundColor().

A text block can also have a list format (if is part of a list); this is accessible using listFormat().

## Member Type Documentation

### enum QTextBlockFormat::Direction

`QTextBlockFormat::LeftToRight` | The text flows from left to right.
`QTextBlockFormat::RightToLeft` | The text flows from right to left.
`QTextBlockFormat::AutoDirection` | The configuration of the system determines the direction.

## Member Function Documentation

### QTextBlockFormat::QTextBlockFormat ()

Constructs a new QTextBlockFormat.

### Qt::Alignment QTextBlockFormat::alignment () const

Returns the paragraph's alignment.

See also setAlignment().

### QColor QTextBlockFormat::backgroundColor () const

Returns the paragraph's background color.

See also setBackgroundColor().

### int QTextBlockFormat::bottomMargin () const

Returns the paragraph's bottom margin.

See also setBottomMargin() and topMargin().

### void QTextBlockFormat::clearBackgroundColor ()

Clears the paragraph's background color. The default background color will be used for the paragraph.

See also backgroundColor() and setBackgroundColor().

### Direction QTextBlockFormat::direction () const

Returns the text's direction.

See also setDirection().

### int QTextBlockFormat::firstLineMargin () const

Returns the paragraph's first line margin.

See also setFirstLineMargin().

### int QTextBlockFormat::indent () const

Returns the paragraph's indent.

See also setIndent().

### bool QTextBlockFormat::isValid () const

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

### int QTextBlockFormat::leftMargin () const

Returns the paragraph's left margin.

See also setLeftMargin(), rightMargin(), and indent().

### bool QTextBlockFormat::nonBreakableLines () const

Returns true if the lines in the paragraph are non-breakable; otherwise returns false.

See also setNonBreakableLines().

### int QTextBlockFormat::rightMargin () const

Returns the paragraph's right margin.

See also setRightMargin() and leftMargin().

### void QTextBlockFormat::setAlignment ( Qt::Alignment alignment )

Sets the paragraph's alignment.

See also alignment().

### void QTextBlockFormat::setBackgroundColor ( const QColor & color )

Sets the paragraph's background color.

See also backgroundColor().

### void QTextBlockFormat::setBottomMargin ( int margin )

Sets the paragraph's bottom margin.

See also bottomMargin(), setTopMargin(), setLeftMargin(), setRightMargin(), and setFirstLineMargin().

### void QTextBlockFormat::setDirection ( Direction direction )

Sets the text's direction to the specified direction.

See also direction().

### void QTextBlockFormat::setFirstLineMargin ( int margin )

Sets the margin for the first line in the block. This allows the first line of a paragraph to be indented differently to the other lines, enhancing the readability of the text.

See also firstLineMargin(), setLeftMargin(), setRightMargin(), setTopMargin(), and setBottomMargin().

### void QTextBlockFormat::setIndent ( int indentation )

Sets the paragraph's indentation. Margins are set independently of indentation with setLeftMargin() and setFirstLineMargin().

See also indent().

### void QTextBlockFormat::setLeftMargin ( int margin )

Sets the paragraph's left margin. Indentation can be applied separately with setIndent().

See also leftMargin(), setRightMargin(), setTopMargin(), setBottomMargin(), and setFirstLineMargin().

### void QTextBlockFormat::setNonBreakableLines ( bool b )

If b is true, the lines in the paragraph are treated as non-breakable; otherwise they are breakable.

See also nonBreakableLines().

### void QTextBlockFormat::setRightMargin ( int margin )

Sets the paragraph's right margin.

See also rightMargin(), setLeftMargin(), setTopMargin(), setBottomMargin(), and setFirstLineMargin().

### void QTextBlockFormat::setTopMargin ( int margin )

Sets the paragraph's top margin.

See also topMargin(), setBottomMargin(), setLeftMargin(), setRightMargin(), and setFirstLineMargin().

### int QTextBlockFormat::topMargin () const

Returns the paragraph's top margin.

See also setTopMargin() and bottomMargin().