Class: QgsTextFragment¶
- class qgis.core.QgsTextFragment(text: str = '', format: QgsTextCharacterFormat = QgsTextCharacterFormat())¶
Bases:
sip.wrapper
Constructor for
QgsTextFragment
, with the specifiedtext
and optional characterformat
.QgsTextFragment(fragment: QTextFragment) Constructor for
QgsTextFragment
, based on the specified QTextFragmentfragment
.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.
Methods
Applies a
capitalization
style to the fragment’s text.Returns the character formatting for the fragment.
Returns the horizontal advance associated with this fragment, when rendered using the specified base
font
.Sets the character
format
for the fragment.Sets the
text
content of the fragment.Returns the text content of the fragment.
- applyCapitalization(self, capitalization: QgsStringUtils.Capitalization)¶
Applies a
capitalization
style to the fragment’s text.New in version 3.16.
- Parameters
capitalization (QgsStringUtils.Capitalization) –
- characterFormat(self) → QgsTextCharacterFormat¶
Returns the character formatting for the fragment.
See also
- Return type
- horizontalAdvance(self, font: QFont, fontHasBeenUpdatedForFragment: bool = False, scaleFactor: float = 1) → float¶
Returns the horizontal advance associated with this fragment, when rendered using the specified base
font
.Set
fontHasBeenUpdatedForFragment
toTrue
iffont
already represents the character format for this fragment.The optional
scaleFactor
parameter can specify a font size scaling factor. It is recommended to set this toQgsTextRenderer
.FONT_WORKAROUND_SCALE 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
font (QFont) –
fontHasBeenUpdatedForFragment (bool = False) –
scaleFactor (float = 1) –
- Return type
float
- setCharacterFormat(self, format: QgsTextCharacterFormat)¶
Sets the character
format
for the fragment.See also
- Parameters
format (QgsTextCharacterFormat) –
- setText(self, text: str)¶
Sets the
text
content of the fragment.See also
- Parameters
text (str) –