|  | Home · All Classes · Modules

# QTextBlockFormat Class Reference
[QtGui module]

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

Inherits QTextFormat.

### Methods

- __init__ (self)
- __init__ (self, QTextBlockFormat)
- Qt.Alignment alignment (self)
- float bottomMargin (self)
- int indent (self)
- bool isValid (self)
- float leftMargin (self)
- bool nonBreakableLines (self)
- QTextFormat.PageBreakFlags pageBreakPolicy (self)
- float rightMargin (self)
- setAlignment (self, Qt.Alignment aalignment)
- setBottomMargin (self, float margin)
- setIndent (self, int aindent)
- setLeftMargin (self, float margin)
- setNonBreakableLines (self, bool b)
- setPageBreakPolicy (self, QTextFormat.PageBreakFlags flags)
- setRightMargin (self, float margin)
- setTabPositions (self, list-of-QTextOption.Tab tabs)
- setTextIndent (self, float margin)
- setTopMargin (self, float margin)
- list-of-QTextOption.Tab tabPositions (self)
- float textIndent (self)
- float topMargin (self)

## Detailed Description

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

A document is composed of a list of blocks, represented by QTextBlock objects. Each block can contain an item of some kind, such as 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(). Overall indentation is set with setIndent(), the indentation of the first line with setTextIndent().

Line breaking can be enabled and disabled with setNonBreakableLines().

The brush used to paint the paragraph's background is set with setBackground(), and other aspects of the text's appearance can be customized by using the setProperty() function with the `OutlinePen`, `ForegroundBrush`, and `BackgroundBrush` QTextFormat.Property values.

If a text block is part of a list, it can also have a list format that is accessible with the listFormat() function.

## Method Documentation

### QTextBlockFormat.__init__ (self)

Constructs a new QTextBlockFormat.

### QTextBlockFormat.__init__ (self, QTextBlockFormat)

### Qt.Alignment QTextBlockFormat.alignment (self)

Returns the paragraph's alignment.

See also setAlignment().

### float QTextBlockFormat.bottomMargin (self)

Returns the paragraph's bottom margin.

See also setBottomMargin() and topMargin().

### int QTextBlockFormat.indent (self)

Returns the paragraph's indent.

See also setIndent().

### bool QTextBlockFormat.isValid (self)

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

### float QTextBlockFormat.leftMargin (self)

Returns the paragraph's left margin.

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

### bool QTextBlockFormat.nonBreakableLines (self)

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

See also setNonBreakableLines().

### QTextFormat.PageBreakFlags QTextBlockFormat.pageBreakPolicy (self)

Returns the currently set page break policy for the paragraph. The default is QTextFormat.PageBreak_Auto.

This function was introduced in Qt 4.2.

See also setPageBreakPolicy().

### float QTextBlockFormat.rightMargin (self)

Returns the paragraph's right margin.

See also setRightMargin() and leftMargin().

### QTextBlockFormat.setAlignment (self, Qt.Alignment aalignment)

Sets the paragraph's alignment.

See also alignment().

### QTextBlockFormat.setBottomMargin (self, float margin)

Sets the paragraph's bottom margin.

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

### QTextBlockFormat.setIndent (self, int aindent)

Sets the paragraph's indentation. Margins are set independently of indentation with setLeftMargin() and setTextIndent(). The indentation is an integer that is multiplied with the document-wide standard indent, resulting in the actual indent of the paragraph.

See also indent() and QTextDocument.indentWidth().

### QTextBlockFormat.setLeftMargin (self, float margin)

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

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

### QTextBlockFormat.setNonBreakableLines (self, bool b)

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

See also nonBreakableLines().

### QTextBlockFormat.setPageBreakPolicy (self, QTextFormat.PageBreakFlags flags)

Sets the page break policy for the paragraph to policy.

This function was introduced in Qt 4.2.

See also pageBreakPolicy().

### QTextBlockFormat.setRightMargin (self, float margin)

Sets the paragraph's right margin.

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

### QTextBlockFormat.setTabPositions (self, list-of-QTextOption.Tab tabs)

Sets the tab positions for the text block to those specified by tabs.

This function was introduced in Qt 4.4.

See also tabPositions().

### QTextBlockFormat.setTextIndent (self, float margin)

Sets the indent 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 textIndent(), setLeftMargin(), setRightMargin(), setTopMargin(), and setBottomMargin().

### QTextBlockFormat.setTopMargin (self, float margin)

Sets the paragraph's top margin.

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

### list-of-QTextOption.Tab QTextBlockFormat.tabPositions (self)

Returns a list of tab positions defined for the text block.

This function was introduced in Qt 4.4.

See also setTabPositions().

### float QTextBlockFormat.textIndent (self)

Returns the paragraph's text indent.

See also setTextIndent().

### float QTextBlockFormat.topMargin (self)

Returns the paragraph's top margin.

See also setTopMargin() and bottomMargin().