Class: QgsTextCharacterFormat¶
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.
Added in version 3.14.
Enums
Status values for boolean format properties |
Methods
Returns the brush used for rendering the background of the fragment. |
|
Returns the path for the image to be used for rendering the background of the fragment. |
|
Returns the font family name, or an empty string if the family is not set and should be inherited. |
|
Returns the font percentage size (as fraction of inherited font size), or -1 if the font size percentage is not set. |
|
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 |
|
Returns |
|
Returns the path to the image to render, if the format applies to a document image fragment. |
|
Returns the image size, if the format applies to a document image fragment. |
|
Returns whether the format has italic enabled. |
|
Returns whether the format has overline enabled. |
|
Override all the default/unset properties of the current character format with the settings from another format. |
|
Sets the brush used for rendering the background of the fragment. |
|
Sets the path for the image to be used for rendering the background of the fragment. |
|
Sets the font family name. |
|
Sets the font percentage size (as fraction of inherited font size). |
|
Sets the font point size. |
|
Sets the font weight. |
|
Sets whether the format has an explicit vertical alignment set. |
|
Sets the path to the image to render, if the format applies to a document image fragment. |
|
Sets the image size, if the format applies to a document image fragment. |
|
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. |
|
Sets the format vertical alignment. |
|
Sets the font word spacing, in points, or NaN if word spacing is not set and should be inherited. |
|
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 given context. |
|
Returns the format vertical alignment. |
|
Returns the font word spacing, in points, or NaN if word spacing is not set and should be inherited. |
- class qgis.core.QgsTextCharacterFormat[source]¶
Bases:
object
- __init__()
- __init__(format: QTextCharFormat)
Constructor for QgsTextCharacterFormat, based on the specified QTextCharFormat
format
.- Parameters:
format (QTextCharFormat)
- __init__(a0: QgsTextCharacterFormat)
- Parameters:
- class BooleanValue(*values)¶
Bases:
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¶
- backgroundBrush(self) QBrush [source]¶
Returns the brush used for rendering the background of the fragment.
Alternatively, the format may have a
backgroundImagePath()
set.See also
See also
Added in version 3.42.
- Return type:
QBrush
- backgroundImagePath(self) str [source]¶
Returns the path for the image to be used for rendering the background of the fragment.
Alternatively, the format may have a
backgroundBrush()
set.See also
See also
Added in version 3.42.
- Return type:
str
- family(self) str [source]¶
Returns the font family name, or an empty string if the family is not set and should be inherited.
See also
Added in version 3.28.
- Return type:
str
- fontPercentageSize(self) float [source]¶
Returns the font percentage size (as fraction of inherited font size), or -1 if the font size percentage is not set.
Note
A format should have either
fontPointSize()
orfontPercentageSize()
set, not both.See also
See also
Added in version 3.40.
- Return type:
float
- fontPointSize(self) float [source]¶
Returns the font point size, or -1 if the font size is not set and should be inherited.
Note
A format should have either
fontPointSize()
orfontPercentageSize()
set, not both.See also
See also
Added in version 3.28.
- Return type:
float
- fontWeight(self) int [source]¶
Returns the font weight, or -1 if the font weight is not set and should be inherited.
See also
Added in version 3.28.
- Return type:
int
- hasBackground(self) bool [source]¶
Returns
True
if the fragment has a background set.See also
Added in version 3.42.
- Return type:
bool
- hasVerticalAlignmentSet(self) bool [source]¶
Returns
True
if the format has an explicit vertical alignment set.If
False
is returned then the vertical alignment will be inherited.See also
See also
Added in version 3.30.
- Return type:
bool
- imagePath(self) str [source]¶
Returns the path to the image to render, if the format applies to a document image fragment.
See also
See also
See also
Added in version 3.40.
- Return type:
str
- imageSize(self) QSizeF [source]¶
Returns the image size, if the format applies to a document image fragment.
The image size is always considered to be in
Qgis
.RenderUnit.Points.See also
See also
See also
Added in version 3.40.
- Return type:
QSizeF
- italic(self) QgsTextCharacterFormat.BooleanValue [source]¶
Returns whether the format has italic enabled.
See also
Added in version 3.28.
- Return type:
- overline(self) QgsTextCharacterFormat.BooleanValue [source]¶
Returns whether the format has overline enabled.
See also
- Return type:
- overrideWith(self, other: QgsTextCharacterFormat)[source]¶
Override all the default/unset properties of the current character format with the settings from another format.
This will replace any default/unset existing settings with the settings from
other
.Any settings which are default/unset in
other
will be left unchanged.- Parameters:
other (QgsTextCharacterFormat) – The format to override with.
Added in version 3.36.
- setBackgroundBrush(self, brush: QBrush | QColor | Qt.GlobalColor | QGradient)[source]¶
Sets the
brush
used for rendering the background of the fragment.Alternatively, the format may have a
backgroundImagePath()
set.See also
Added in version 3.42.
- Parameters:
brush (Union[QBrush, Union[QColor, Qt.GlobalColor], QGradient])
- setBackgroundImagePath(self, path: str | None)[source]¶
Sets the
path
for the image to be used for rendering the background of the fragment.Alternatively, the format may have a
backgroundBrush()
set.See also
Added in version 3.42.
- Parameters:
path (Optional[str])
- setFamily(self, family: str | None)[source]¶
Sets the font
family
name.Set to an empty string if the family should be inherited.
See also
Added in version 3.28.
- Parameters:
family (Optional[str])
- setFontPercentageSize(self, size: float)[source]¶
Sets the font percentage
size
(as fraction of inherited font size).Set
size
to -1 if the font percentange size is not set.Note
A format should have either
fontPointSize()
orfontPercentageSize()
set, not both.See also
See also
Added in version 3.40.
- Parameters:
size (float)
- setFontPointSize(self, size: float)[source]¶
Sets the font point
size
.Set
size
to -1 if the font size is not set and should be inherited.Note
A format should have either
fontPointSize()
orfontPercentageSize()
set, not both.See also
See also
Added in version 3.28.
- Parameters:
size (float)
- setFontWeight(self, fontWeight: int)[source]¶
Sets the font
weight
.Set
weight
to -1 if the font weight is not set and should be inherited.See also
Added in version 3.28.
- Parameters:
fontWeight (int)
- setHasVerticalAlignmentSet(self, set: bool)[source]¶
Sets whether the format has an explicit vertical alignment
set
.If
set
isFalse
then the vertical alignment will be inherited.See also
See also
Added in version 3.30.
- Parameters:
set (bool)
- setImagePath(self, path: str | None)[source]¶
Sets the
path
to the image to render, if the format applies to a document image fragment.See also
See also
See also
Added in version 3.40.
- Parameters:
path (Optional[str])
- setImageSize(self, size: QSizeF)[source]¶
Sets the image
size
, if the format applies to a document image fragment.The image size is always considered to be in
Qgis
.RenderUnit.Points.See also
See also
See also
Added in version 3.40.
- Parameters:
size (QSizeF)
- setItalic(self, enabled: QgsTextCharacterFormat.BooleanValue)[source]¶
Sets whether the format has italic
enabled
.See also
Added in version 3.28.
- Parameters:
enabled (QgsTextCharacterFormat.BooleanValue)
- setOverline(self, enabled: QgsTextCharacterFormat.BooleanValue)[source]¶
Sets whether the format has overline
enabled
.See also
- Parameters:
enabled (QgsTextCharacterFormat.BooleanValue)
- setStrikeOut(self, enabled: QgsTextCharacterFormat.BooleanValue)[source]¶
Sets whether the format has strikethrough
enabled
.See also
- Parameters:
enabled (QgsTextCharacterFormat.BooleanValue)
- setTextColor(self, textColor: QColor | Qt.GlobalColor)[source]¶
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, Qt.GlobalColor])
- setUnderline(self, enabled: QgsTextCharacterFormat.BooleanValue)[source]¶
Sets whether the format has underline
enabled
.See also
- Parameters:
enabled (QgsTextCharacterFormat.BooleanValue)
- setVerticalAlignment(self, alignment: Qgis.TextCharacterVerticalAlignment)[source]¶
Sets the format vertical
alignment
.This property is only respected if
hasVerticalAlignmentSet()
isTrue
.See also
See also
Added in version 3.30.
- Parameters:
alignment (Qgis.TextCharacterVerticalAlignment)
- setWordSpacing(self, spacing: float)[source]¶
Sets the font word
spacing
, in points, or NaN if word spacing is not set and should be inherited.See also
Added in version 3.40.
- Parameters:
spacing (float)
- strikeOut(self) QgsTextCharacterFormat.BooleanValue [source]¶
Returns whether the format has strikethrough enabled.
See also
- Return type:
- textColor(self) QColor [source]¶
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 [source]¶
Returns whether the format has underline enabled.
See also
- Return type:
- updateFontForFormat(self, font: QFont, context: QgsRenderContext, scaleFactor: float = 1)[source]¶
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.calculateScaleFactorForFormat()
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)
- verticalAlignment(self) Qgis.TextCharacterVerticalAlignment [source]¶
Returns the format vertical alignment.
This property is only respected if
hasVerticalAlignmentSet()
isTrue
.See also
See also
Added in version 3.30.
- Return type: