Table Of Contents

Previous topic

QTextListFormat

Next topic

QTextLength

QTextBlockFormat

Synopsis

Functions

Detailed Description

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

A document is composed of a list of blocks, represented by PySide.QtGui.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 PySide.QtGui.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 PySide.QtGui.QTextBlockFormat.setAlignment() . Margins are controlled by PySide.QtGui.QTextBlockFormat.setTopMargin() , PySide.QtGui.QTextBlockFormat.setBottomMargin() , PySide.QtGui.QTextBlockFormat.setLeftMargin() , PySide.QtGui.QTextBlockFormat.setRightMargin() . Overall indentation is set with PySide.QtGui.QTextBlockFormat.setIndent() , the indentation of the first line with PySide.QtGui.QTextBlockFormat.setTextIndent() .

Line spacing is set with PySide.QtGui.QTextBlockFormat.setLineHeight() and retrieved via PySide.QtGui.QTextBlockFormat.lineHeight() and PySide.QtGui.QTextBlockFormat.lineHeightType() . The types of line spacing available are in the QTextBlockFormat.LineHeightTypes enum.

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

The brush used to paint the paragraph’s background is set with PySide.QtGui.QTextFormat.setBackground() , and other aspects of the text’s appearance can be customized by using the PySide.QtGui.QTextFormat.setProperty() function with the OutlinePen , ForegroundBrush , and BackgroundBrushQTextFormat.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.

class PySide.QtGui.QTextBlockFormat
class PySide.QtGui.QTextBlockFormat(QTextBlockFormat)
class PySide.QtGui.QTextBlockFormat(fmt)
Parameters:

Constructs a new PySide.QtGui.QTextBlockFormat .

Creates a new block format with the same attributes as the given text format.

PySide.QtGui.QTextBlockFormat.LineHeightTypes

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

Constant Description
QTextBlockFormat.SingleHeight This is the default line height: single spacing.
QTextBlockFormat.ProportionalHeight This sets the spacing proportional to the line (in percentage). For example, set to 200 for double spacing.
QTextBlockFormat.FixedHeight This sets the line height to a fixed line height (in pixels).
QTextBlockFormat.MinimumHeight This sets the minimum line height (in pixels).
QTextBlockFormat.LineDistanceHeight This adds the specified height between lines (in pixels).

Note

This enum was introduced or modified in Qt 4.8

PySide.QtGui.QTextBlockFormat.alignment()
Return type:PySide.QtCore.Qt.Alignment

Returns the paragraph’s alignment.

PySide.QtGui.QTextBlockFormat.bottomMargin()
Return type:PySide.QtCore.qreal

Returns the paragraph’s bottom margin.

PySide.QtGui.QTextBlockFormat.indent()
Return type:PySide.QtCore.int

Returns the paragraph’s indent.

PySide.QtGui.QTextBlockFormat.leftMargin()
Return type:PySide.QtCore.qreal

Returns the paragraph’s left margin.

PySide.QtGui.QTextBlockFormat.lineHeight(scriptLineHeight, scaling)
Parameters:
  • scriptLineHeightPySide.QtCore.qreal
  • scalingPySide.QtCore.qreal
Return type:

PySide.QtCore.qreal

Returns the height of the lines in the paragraph based on the height of the script line given by scriptLineHeight and the specified scaling factor.

The value that is returned is also dependent on the given LineHeightType of the paragraph as well as the LineHeight setting that has been set for the paragraph.

The scaling is needed for heights that include a fixed number of pixels, to scale them appropriately for printing.

PySide.QtGui.QTextBlockFormat.lineHeight()
Return type:PySide.QtCore.qreal

This returns the LineHeight property for the paragraph.

PySide.QtGui.QTextBlockFormat.lineHeightType()
Return type:PySide.QtCore.int

This returns the LineHeightType property of the paragraph.

PySide.QtGui.QTextBlockFormat.nonBreakableLines()
Return type:PySide.QtCore.bool

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

PySide.QtGui.QTextBlockFormat.pageBreakPolicy()
Return type:PySide.QtGui.QTextFormat.PageBreakFlags

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

PySide.QtGui.QTextBlockFormat.rightMargin()
Return type:PySide.QtCore.qreal

Returns the paragraph’s right margin.

PySide.QtGui.QTextBlockFormat.setAlignment(alignment)
Parameters:alignmentPySide.QtCore.Qt.Alignment
PySide.QtGui.QTextBlockFormat.setBottomMargin(margin)
Parameters:marginPySide.QtCore.qreal

Sets the paragraph’s bottom margin .

PySide.QtGui.QTextBlockFormat.setIndent(indent)
Parameters:indentPySide.QtCore.int

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

PySide.QtGui.QTextBlockFormat.setLeftMargin(margin)
Parameters:marginPySide.QtCore.qreal

Sets the paragraph’s left margin . Indentation can be applied separately with PySide.QtGui.QTextBlockFormat.setIndent() .

PySide.QtGui.QTextBlockFormat.setLineHeight(height, heightType)
Parameters:
  • heightPySide.QtCore.qreal
  • heightTypePySide.QtCore.int

Sets the line height for the paragraph to the value given by height which is dependent on heightType in the way described by the QTextBlockFormat.LineHeightTypes enum.

PySide.QtGui.QTextBlockFormat.setNonBreakableLines(b)
Parameters:bPySide.QtCore.bool

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

PySide.QtGui.QTextBlockFormat.setPageBreakPolicy(flags)
Parameters:flagsPySide.QtGui.QTextFormat.PageBreakFlags
PySide.QtGui.QTextBlockFormat.setRightMargin(margin)
Parameters:marginPySide.QtCore.qreal

Sets the paragraph’s right margin .

PySide.QtGui.QTextBlockFormat.setTabPositions(tabs)
Parameters:tabs
PySide.QtGui.QTextBlockFormat.setTextIndent(aindent)
Parameters:aindentPySide.QtCore.qreal

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.

PySide.QtGui.QTextBlockFormat.setTopMargin(margin)
Parameters:marginPySide.QtCore.qreal

Sets the paragraph’s top margin .

PySide.QtGui.QTextBlockFormat.tabPositions()
Return type:

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

PySide.QtGui.QTextBlockFormat.textIndent()
Return type:PySide.QtCore.qreal

Returns the paragraph’s text indent.

PySide.QtGui.QTextBlockFormat.topMargin()
Return type:PySide.QtCore.qreal

Returns the paragraph’s top margin.