Class: QgsTextBlock

Represents a block of text consisting of one or more QgsTextFragment objects.

Warning

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

Added in version 3.14.

class qgis.core.QgsTextBlock[source]

Bases: object

__init__()

Constructor for an empty text block.

__init__(fragment: QgsTextFragment)

Constructor for a QgsTextBlock consisting of a single text fragment.

Parameters:

fragment (QgsTextFragment)

__init__(a0: QgsTextBlock)
Parameters:

a0 (QgsTextBlock)

append(self, fragment: QgsTextFragment)[source]

Appends a fragment to the block.

Parameters:

fragment (QgsTextFragment)

applyCapitalization(self, capitalization: Qgis.Capitalization)[source]

Applies a capitalization style to the block’s text.

Added in version 3.16.

Parameters:

capitalization (Qgis.Capitalization)

at(self, index: int) QgsTextFragment

Returns the fragment at the specified index.

Raises:

KeyError – if no fragment exists at the specified index.

Parameters:

index (int)

Return type:

QgsTextFragment

blockFormat(self) QgsTextBlockFormat

Returns the block formatting for the fragment.

See also

setBlockFormat()

Added in version 3.40.

Return type:

QgsTextBlockFormat

clear(self)[source]

Clears the block, removing all its contents.

empty(self) bool[source]

Returns True if the block is empty.

Return type:

bool

static fromPlainText(text: str | None, format: QgsTextCharacterFormat = QgsTextCharacterFormat()) QgsTextBlock[source]

Constructor for QgsTextBlock consisting of a plain text, and optional character format.

If text contains tab characters they will be appended as separate text fragments within the block, consisting of just the tab character.

Added in version 3.38.

Parameters:
Return type:

QgsTextBlock

hasBackgrounds(self) bool[source]

Returns True if the block or any of the fragments in the block have background brushes set.

Added in version 3.42.

Return type:

bool

insert(self, index: int, fragment: QgsTextFragment)[source]

Inserts a fragment into the block, at the specified index.

Raises:

IndexError – if no fragment exists at the specified index.

Added in version 3.40.

Parameters:
reserve(self, count: int)[source]

Reserves the specified count of fragments for optimised fragment appending.

Added in version 3.40.

Parameters:

count (int)

setBlockFormat(self, format: QgsTextBlockFormat)[source]

Sets the block format for the fragment.

See also

blockFormat()

Added in version 3.40.

Parameters:

format (QgsTextBlockFormat)

size(self) int[source]

Returns the number of fragments in the block.

Return type:

int

toPlainText(self) str[source]

Converts the block to plain text.

Added in version 3.16.

Return type:

str