Class: QgsTextBlockFormat

Stores information relating to individual block formatting.

These options encapsulate formatting options which override the default settings from a QgsTextFormat for individual text blocks.

Warning

This API is not considered stable and may change in future QGIS versions.

Added in version 3.40.

Enums

BooleanValue

Status values for boolean format properties

Methods

hasHorizontalAlignmentSet

Returns True if the format has an explicit horizontal alignment set.

horizontalAlignment

Returns the format horizontal alignment.

overrideWith

Override all the default/unset properties of the current block format with the settings from another format.

setHasHorizontalAlignmentSet

Sets whether the format has an explicit horizontal alignment set.

setHorizontalAlignment

Sets the format horizontal alignment.

updateFontForFormat

Updates the specified font in place, applying block formatting options which are applicable on a font level when rendered in the given context.

class qgis.core.QgsTextBlockFormat[source]

Bases: object

__init__()
__init__(format: QTextBlockFormat)

Constructor for QgsTextBlockFormat, based on the specified QTextBlockFormat format.

Parameters:

format (QTextBlockFormat)

__init__(a0: QgsTextBlockFormat)
Parameters:

a0 (QgsTextBlockFormat)

class BooleanValue(*values)

Bases: IntEnum

Status values for boolean format properties

  • NotSet: Property is not set

  • SetTrue: Property is set and True

  • SetFalse: Property is set and False

NotSet = 0
SetFalse = 2
SetTrue = 1
hasHorizontalAlignmentSet(self) bool[source]

Returns True if the format has an explicit horizontal alignment set.

If False is returned then the horizontal alignment will be inherited.

Return type:

bool

horizontalAlignment(self) Qgis.TextHorizontalAlignment[source]

Returns the format horizontal alignment.

This property is only respected if hasHorizontalAlignmentSet() is True.

Return type:

Qgis.TextHorizontalAlignment

overrideWith(self, other: QgsTextBlockFormat)[source]

Override all the default/unset properties of the current block format with the settings from another format.

This will replace any default/unset existing settings with the settings from other.

Any settings which are default/unset in other will be left unchanged.

Parameters:

other (QgsTextBlockFormat) – The format to override with.

setHasHorizontalAlignmentSet(self, set: bool)[source]

Sets whether the format has an explicit horizontal alignment set.

If set is False then the horizontal alignment will be inherited.

Parameters:

set (bool)

setHorizontalAlignment(self, alignment: Qgis.TextHorizontalAlignment)[source]

Sets the format horizontal alignment.

This property is only respected if hasHorizontalAlignmentSet() is True.

Parameters:

alignment (Qgis.TextHorizontalAlignment)

updateFontForFormat(self, font: QFont, context: QgsRenderContext, scaleFactor: float = 1)[source]

Updates the specified font in place, applying block formatting options which are applicable on a font level when rendered in the given context.

The optional scaleFactor parameter can specify a font size scaling factor. It is recommended to set this to QgsTextRenderer.calculateScaleFactorForFormat() and then manually calculations based on the resultant font metrics. Failure to do so will result in poor quality text rendering at small font sizes.

Parameters: