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.
Methods
Appends a fragment to the block.  | 
|
Applies a capitalization style to the block's text.  | 
|
Returns the fragment at the specified index.  | 
|
Returns the block formatting for the fragment.  | 
|
Clears the block, removing all its contents.  | 
|
Returns   | 
|
Inserts a fragment into the block, at the specified index.  | 
|
Reserves the specified count of fragments for optimised fragment appending.  | 
|
Sets the block format for the fragment.  | 
|
Returns the number of fragments in the block.  | 
|
Converts the block to plain text.  | 
Static Methods
Constructor for   | 
- 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
fragmentto the block.- Parameters:
 fragment (QgsTextFragment)
- applyCapitalization(self, capitalization: Qgis.Capitalization)[source]¶
 Applies a
capitalizationstyle 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:
 
- blockFormat(self) QgsTextBlockFormat¶
 Returns the block formatting for the fragment.
See also
Added in version 3.40.
- Return type:
 
- static fromPlainText(text: str | None, format: QgsTextCharacterFormat = QgsTextCharacterFormat()) QgsTextBlock[source]¶
 Constructor for
QgsTextBlockconsisting of a plaintext, and optional characterformat.If
textcontains 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:
 text (Optional[str])
format (
QgsTextCharacterFormat= QgsTextCharacterFormat())
- Return type:
 
- insert(self, index: int, fragment: QgsTextFragment)[source]¶
 Inserts a
fragmentinto the block, at the specified index.- Raises:
 IndexError – if no fragment exists at the specified index.
Added in version 3.40.
- Parameters:
 index (int)
fragment (QgsTextFragment)
- reserve(self, count: int)[source]¶
 Reserves the specified
countof fragments for optimised fragment appending.Added in version 3.40.
- Parameters:
 count (int)
- setBlockFormat(self, format: QgsTextBlockFormat)[source]¶
 Sets the block
formatfor the fragment.See also
Added in version 3.40.
- Parameters:
 format (QgsTextBlockFormat)