Class: QgsTextFragment

class qgis.core.QgsTextFragment(text: str = '', format: QgsTextCharacterFormat = QgsTextCharacterFormat())

Bases: sip.wrapper

Constructor for QgsTextFragment, with the specified text and optional character format.

QgsTextFragment(fragment: QTextFragment) Constructor for QgsTextFragment, based on the specified QTextFragment fragment.

QgsTextFragment(QgsTextFragment)

Stores a fragment of text along with formatting overrides to be used when rendering the fragment.

Warning

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

New in version 3.14.

Parameters
  • text (str = '') –

  • format

characterFormat(self)QgsTextCharacterFormat

Returns the character formatting for the fragment.

Return type

QgsTextCharacterFormat

horizontalAdvance(self, font: QFont, fontHasBeenUpdatedForFragment: bool = False) → float

Returns the horizontal advance associated with this fragment, when rendered using the specified base font.

Set fontHasBeenUpdatedForFragment to True if font already represents the character format for this fragment.

Parameters
  • font (QFont) –

  • fontHasBeenUpdatedForFragment (bool = False) –

Return type

float

setCharacterFormat(self, format: QgsTextCharacterFormat)

Sets the character format for the fragment.

Parameters

format (QgsTextCharacterFormat) –

setText(self, text: str)

Sets the text content of the fragment.

See also

text()

Parameters

text (str) –

text(self) → str

Returns the text content of the fragment.

See also

setText()

Return type

str