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 QTextCharFormatformat
.QgsTextCharacterFormat(
QgsTextCharacterFormat
)Enums
Bases:
enum.IntEnum
Methods
Returns the font family name, or an empty string if the family is not set and should be inherited.
Returns the font point size, or -1 if the font size is not set and should be inherited.
Returns the font weight, or -1 if the font weight is not set and should be inherited.
Returns whether the format has italic enabled.
Returns whether the format has overline enabled.
Sets the font
family
name.Sets the font point
size
.Sets the font
weight
.Sets whether the format has italic
enabled
.Sets whether the format has overline
enabled
.Sets whether the format has strikethrough
enabled
.Sets the character's text
color
.Sets whether the format has underline
enabled
.Returns whether the format has strikethrough enabled.
Returns the character's text color, or an invalid color if no color override is set and the default format color should be used.
Returns whether the format has underline enabled.
Updates the specified
font
in place, applying character formatting options which are applicable on a font level when rendered in the givencontext
.- class BooleanValue(value)¶
Bases:
enum.IntEnum
Status values for boolean format properties
NotSet
: Property is not setSetTrue
: Property is set andTrue
SetFalse
: Property is set andFalse
- 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
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.
See also
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
New in version 3.28.
- Return type:
int
- italic(self) QgsTextCharacterFormat.BooleanValue ¶
Returns whether the format has italic enabled.
See also
New in version 3.28.
- Return type:
- overline(self) QgsTextCharacterFormat.BooleanValue ¶
Returns whether the format has overline enabled.
See also
- Return type:
- setFamily(self, family: str)¶
Sets the font
family
name.Set to an empty string if the family should be inherited.
See also
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
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
New in version 3.28.
- Parameters:
fontWeight (int) –
- setItalic(self, enabled: QgsTextCharacterFormat.BooleanValue)¶
Sets whether the format has italic
enabled
.See also
New in version 3.28.
- Parameters:
enabled (QgsTextCharacterFormat.BooleanValue) –
- setOverline(self, enabled: QgsTextCharacterFormat.BooleanValue)¶
Sets whether the format has overline
enabled
.See also
- Parameters:
enabled (QgsTextCharacterFormat.BooleanValue) –
- setStrikeOut(self, enabled: QgsTextCharacterFormat.BooleanValue)¶
Sets whether the format has strikethrough
enabled
.See also
- 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
- Parameters:
textColor (Union[QColor) –
- setUnderline(self, enabled: QgsTextCharacterFormat.BooleanValue)¶
Sets whether the format has underline
enabled
.See also
- Parameters:
enabled (QgsTextCharacterFormat.BooleanValue) –
- strikeOut(self) QgsTextCharacterFormat.BooleanValue ¶
Returns whether the format has strikethrough enabled.
See also
- Return type:
- 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
- Return type:
QColor
- underline(self) QgsTextCharacterFormat.BooleanValue ¶
Returns whether the format has underline enabled.
See also
- Return type:
- 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 givencontext
.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) –
context (QgsRenderContext) –
scaleFactor (float = 1) –