QTextBlockFormat¶

PyQt5.QtGui.QTextBlockFormat

Inherits from QTextFormat.

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 spacing is set with setLineHeight() and retrieved via lineHeight() and lineHeightType(). The types of line spacing available are in the LineHeightTypes enum.

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 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.

Enums¶

LineHeightTypes

This enum describes the various types of line spacing support paragraphs can have.

Member

Value

Description

FixedHeight

2

This sets the line height to a fixed line height (in pixels).

LineDistanceHeight

4

This adds the specified height between lines (in pixels).

MinimumHeight

3

This sets the minimum line height (in pixels).

ProportionalHeight

1

This sets the spacing proportional to the line (in percentage). For example, set to 200 for double spacing.

SingleHeight

0

This is the default line height: single spacing.


MarkerType

TODO

Member

Value

Description

Checked

TODO

TODO

NoMarker

TODO

TODO

Unchecked

TODO

TODO

Methods¶

__init__()

TODO


__init__(QTextBlockFormat)

TODO


alignment() → Alignment

See also

setAlignment().


bottomMargin() → float

See also

setBottomMargin().


headingLevel() → int

TODO


indent() → int

See also

setIndent().


isValid() → bool

TODO


leftMargin() → float

See also

setLeftMargin().


lineHeight() → float

TODO


lineHeight(float, scaling: float = 1) → float

See also

setLineHeight().


lineHeightType() → int

TODO


marker() → MarkerType

TODO


nonBreakableLines() → bool

pageBreakPolicy() → PageBreakFlags

rightMargin() → float

See also

setRightMargin().


setAlignment(Union[Alignment, AlignmentFlag])

See also

alignment().


setBottomMargin(float)

See also

bottomMargin().


setHeadingLevel(int)

TODO


setIndent(int)

See also

indent().


setLeftMargin(float)

See also

leftMargin().


setLineHeight(float, int)

See also

lineHeight().


setMarker(MarkerType)

TODO


setNonBreakableLines(bool)

setPageBreakPolicy(Union[PageBreakFlags, PageBreakFlag])

See also

pageBreakPolicy().


setRightMargin(float)

See also

rightMargin().


setTabPositions(Iterable[Tab])

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

See also

tabPositions().


setTextIndent(float)

See also

textIndent().


setTopMargin(float)

See also

topMargin().


tabPositions() → List[Tab]

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

See also

setTabPositions().


textIndent() → float

See also

setTextIndent().


topMargin() → float

See also

setTopMargin().