Class: QgsTextCharacterFormat

class qgis.core.QgsTextCharacterFormat

Bases: sip.wrapper

Stores information relating to individual character formatting.

These options encapsulate formatting options which override the default settings from a QgsTextFormat for individual characters (or sets of characters).

Warning

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

New in version 3.14.

QgsTextCharacterFormat() Constructor for QgsTextCharacterFormat.

QgsTextCharacterFormat(format: QTextCharFormat) Constructor for QgsTextCharacterFormat, based on the specified QTextCharFormat format.

QgsTextCharacterFormat(QgsTextCharacterFormat)

Enums

BooleanValue

Bases: enum.IntEnum

Methods

family

Returns the font family name, or an empty string if the family is not set and should be inherited.

fontPointSize

Returns the font point size, or -1 if the font size is not set and should be inherited.

fontWeight

Returns the font weight, or -1 if the font weight is not set and should be inherited.

italic

Returns whether the format has italic enabled.

overline

Returns whether the format has overline enabled.

setFamily

Sets the font family name.

setFontPointSize

Sets the font point size.

setFontWeight

Sets the font weight.

setItalic

Sets whether the format has italic enabled.

setOverline

Sets whether the format has overline enabled.

setStrikeOut

Sets whether the format has strikethrough enabled.

setTextColor

Sets the character's text color.

setUnderline

Sets whether the format has underline enabled.

strikeOut

Returns whether the format has strikethrough enabled.

textColor

Returns the character's text color, or an invalid color if no color override is set and the default format color should be used.

underline

Returns whether the format has underline enabled.

updateFontForFormat

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

class BooleanValue(value)

Bases: enum.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
family(self) str

Returns the font family name, or an empty string if the family is not set and should be inherited.

See also

setFamily()

New in version 3.28.

Return type:

str

fontPointSize(self) float

Returns the font point size, or -1 if the font size is not set and should be inherited.

New in version 3.28.

Return type:

float

fontWeight(self) int

Returns the font weight, or -1 if the font weight is not set and should be inherited.

See also

setFontWeight()

New in version 3.28.

Return type:

int

italic(self) QgsTextCharacterFormat.BooleanValue

Returns whether the format has italic enabled.

See also

setItalic()

New in version 3.28.

Return type:

QgsTextCharacterFormat.BooleanValue

overline(self) QgsTextCharacterFormat.BooleanValue

Returns whether the format has overline enabled.

See also

setUnderline()

Return type:

QgsTextCharacterFormat.BooleanValue

setFamily(self, family: str)

Sets the font family name.

Set to an empty string if the family should be inherited.

See also

family()

New in version 3.28.

Parameters:

family (str) –

setFontPointSize(self, size: float)

Sets the font point size.

Set size to -1 if the font size is not set and should be inherited.

See also

fontPointSize()

New in version 3.28.

Parameters:

size (float) –

setFontWeight(self, fontWeight: int)

Sets the font weight.

Set weight to -1 if the font weight is not set and should be inherited.

See also

fontWeight()

New in version 3.28.

Parameters:

fontWeight (int) –

setItalic(self, enabled: QgsTextCharacterFormat.BooleanValue)

Sets whether the format has italic enabled.

See also

italic()

New in version 3.28.

Parameters:

enabled (QgsTextCharacterFormat.BooleanValue) –

setOverline(self, enabled: QgsTextCharacterFormat.BooleanValue)

Sets whether the format has overline enabled.

See also

overline()

Parameters:

enabled (QgsTextCharacterFormat.BooleanValue) –

setStrikeOut(self, enabled: QgsTextCharacterFormat.BooleanValue)

Sets whether the format has strikethrough enabled.

See also

strikeOut()

Parameters:

enabled (QgsTextCharacterFormat.BooleanValue) –

setTextColor(self, textColor: QColor | Qt.GlobalColor)

Sets the character’s text color.

Set color to an invalid color if no color override is desired and the default format color should be used.

See also

textColor()

Parameters:

textColor (Union[QColor) –

setUnderline(self, enabled: QgsTextCharacterFormat.BooleanValue)

Sets whether the format has underline enabled.

See also

underline()

Parameters:

enabled (QgsTextCharacterFormat.BooleanValue) –

strikeOut(self) QgsTextCharacterFormat.BooleanValue

Returns whether the format has strikethrough enabled.

See also

setStrikeOut()

Return type:

QgsTextCharacterFormat.BooleanValue

textColor(self) QColor

Returns the character’s text color, or an invalid color if no color override is set and the default format color should be used.

See also

setTextColor()

Return type:

QColor

underline(self) QgsTextCharacterFormat.BooleanValue

Returns whether the format has underline enabled.

See also

setUnderline()

Return type:

QgsTextCharacterFormat.BooleanValue

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

Updates the specified font in place, applying character 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.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: