Class: QgsTextFormat¶
-
class
qgis.core.
QgsTextFormat
¶ Bases:
sip.wrapper
QgsTextFormat(other:
QgsTextFormat
) Copy constructor.- Parameters
other – source QgsTextFormat
Container for all settings relating to text rendering.
Note
QgsTextFormat
objects are implicitly shared.Methods
Returns a reference to the text background settings.
Returns the blending mode used for drawing the text.
Returns a reference to the text buffer settings.
Returns the color that text will be rendered in.
Returns
True
if any component of the font format requires advanced effects such as blend modes, which require output in raster formats to be fully respected.Returns a reference to the format’s property collection, used for data defined overrides.
Returns the font used for rendering text.
Returns
True
if the specified font was found on the system, orFalse
if the font was not found and a replacement was used instead.Attempts to parse the provided mime
data
as a QgsTextFormat.Returns a text format matching the settings from an input
font
.Returns the line height for text.
Returns the named style for the font used for rendering text (e.g., “bold”).
Returns the text’s opacity.
Returns the orientation of the text.
Returns the background color for text previews.
Reads settings from a layer’s custom properties (for QGIS 2.x projects).
Read settings from a DOM element.
Returns the family for the resolved font, ie if the specified font was not found on the system this will return the name of the replacement font.
Returns a font with the size scaled to match the format’s size settings (including units and map unit scale) for a specified render context.
Sets the text’s background settings.q
Sets the blending mode used for drawing the text.
Sets the text’s buffer settings.
Sets the color that text will be rendered in.
Sets the format’s property collection, used for data defined overrides.
Sets the font used for rendering text.
Sets the line height for text.
Sets the named style for the font used for rendering text.
Sets the text’s opacity.
Sets the
orientation
for the text.Sets the background
color
that text will be rendered on for previews.Sets the text’s drop shadow settings.
Sets the size for rendered text.
Sets the map unit scale object for the size.
Sets the units for the size of rendered text.
Returns a reference to the text drop shadow settings.
Returns the size for rendered text.
Returns the map unit scale object for the size.
Returns the units for the size of rendered text.
Returns a pixmap preview for a text
format
.Returns new mime data representing the text format settings.
Returns a QFont matching the relevant settings from this text format.
Updates the format by evaluating current values of data defined properties.
Write settings into a DOM element.
Attributes
-
HorizontalOrientation
= 0¶
-
RotationBasedOrientation
= 2¶
-
class
TextOrientation
¶ Bases:
int
-
VerticalOrientation
= 1¶
-
background
(self) → QgsTextBackgroundSettings¶ Returns a reference to the text background settings.
See also
- Return type
-
blendMode
(self) → QPainter.CompositionMode¶ Returns the blending mode used for drawing the text.
See also
- Return type
QPainter.CompositionMode
-
buffer
(self) → QgsTextBufferSettings¶ Returns a reference to the text buffer settings.
See also
- Return type
-
color
(self) → QColor¶ Returns the color that text will be rendered in.
See also
- Return type
QColor
-
containsAdvancedEffects
(self) → bool¶ Returns
True
if any component of the font format requires advanced effects such as blend modes, which require output in raster formats to be fully respected.- Return type
bool
-
dataDefinedProperties
(self) → QgsPropertyCollection¶ Returns a reference to the format’s property collection, used for data defined overrides.
See also
New in version 3.10.
- Return type
-
font
(self) → QFont¶ Returns the font used for rendering text. Note that the size of the font is not used, and size() should be called instead to determine the size of rendered text.
See also
See also
See also
See also
- Return type
QFont
-
fontFound
(self) → bool¶ Returns
True
if the specified font was found on the system, orFalse
if the font was not found and a replacement was used instead.See also
- Return type
bool
-
fromMimeData
(data: QMimeData) → Tuple[QgsTextFormat, bool]¶ Attempts to parse the provided mime
data
as a QgsTextFormat. If data can be parsed as a text format,ok
will be set toTrue
.See also
- Parameters
data (QMimeData) –
- Return type
Tuple[
QgsTextFormat
, bool]
-
fromQFont
(font: QFont) → QgsTextFormat¶ Returns a text format matching the settings from an input
font
. Unlike setFont(), this method also handles the size and size units fromfont
.See also
New in version 3.2.
- Parameters
font (QFont) –
- Return type
-
lineHeight
(self) → float¶ Returns the line height for text. This is a number between 0.0 and 10.0 representing the leading between lines as a multiplier of line height.
See also
- Return type
float
-
namedStyle
(self) → str¶ Returns the named style for the font used for rendering text (e.g., “bold”).
See also
See also
- Return type
str
-
opacity
(self) → float¶ Returns the text’s opacity. The opacity is a double value between 0 (fully transparent) and 1 (totally opaque).
See also
- Return type
float
-
orientation
(self) → QgsTextFormat.TextOrientation¶ Returns the orientation of the text.
See also
New in version 3.10.
- Return type
-
previewBackgroundColor
(self) → QColor¶ Returns the background color for text previews.
See also
New in version 3.10.
- Return type
QColor
-
readFromLayer
(self, layer: QgsVectorLayer)¶ Reads settings from a layer’s custom properties (for QGIS 2.x projects).
- Parameters
layer (QgsVectorLayer) – source vector layer
-
readXml
(self, elem: QDomElement, context: QgsReadWriteContext)¶ Read settings from a DOM element.
See also
- Parameters
elem (QDomElement) –
context (QgsReadWriteContext) –
-
resolvedFontFamily
(self) → str¶ Returns the family for the resolved font, ie if the specified font was not found on the system this will return the name of the replacement font.
See also
- Return type
str
-
scaledFont
(self, context: QgsRenderContext) → QFont¶ Returns a font with the size scaled to match the format’s size settings (including units and map unit scale) for a specified render context.
- Parameters
context (QgsRenderContext) – destination render context
- Return type
QFont
- Returns
font with scaled size
See also
See also
-
setBackground
(self, backgroundSettings: QgsTextBackgroundSettings)¶ Sets the text’s background settings.q
- Parameters
backgroundSettings (QgsTextBackgroundSettings) – background settings
See also
-
setBlendMode
(self, mode: QPainter.CompositionMode)¶ Sets the blending mode used for drawing the text.
- Parameters
mode (QPainter.CompositionMode) – blending mode
See also
-
setBuffer
(self, bufferSettings: QgsTextBufferSettings)¶ Sets the text’s buffer settings.
- Parameters
bufferSettings (QgsTextBufferSettings) – buffer settings
See also
-
setColor
(self, color: Union[QColor, Qt.GlobalColor, QGradient])¶ Sets the color that text will be rendered in.
- Parameters
color (Union[QColor) – text color
See also
-
setDataDefinedProperties
(self, collection: QgsPropertyCollection)¶ Sets the format’s property collection, used for data defined overrides.
- Parameters
collection (QgsPropertyCollection) – property collection. Existing properties will be replaced.
See also
New in version 3.10.
-
setFont
(self, font: QFont)¶ Sets the font used for rendering text. Note that the size of the font is not used, and setSize() should be called instead to explicitly set the size of rendered text.
- Parameters
font (QFont) – desired font
See also
See also
See also
-
setLineHeight
(self, height: float)¶ Sets the line height for text.
- Parameters
height (float) – a number between 0.0 and 10.0 representing the leading between lines as a multiplier of line height.
See also
-
setNamedStyle
(self, style: str)¶ Sets the named style for the font used for rendering text.
- Parameters
style (str) – named style, e.g., “bold”
See also
See also
-
setOpacity
(self, opacity: float)¶ Sets the text’s opacity.
- Parameters
opacity (float) – opacity as a double value between 0 (fully transparent) and 1 (totally opaque)
See also
-
setOrientation
(self, orientation: QgsTextFormat.TextOrientation)¶ Sets the
orientation
for the text.See also
New in version 3.10.
- Parameters
orientation (QgsTextFormat.TextOrientation) –
-
setPreviewBackgroundColor
(self, color: Union[QColor, Qt.GlobalColor, QGradient])¶ Sets the background
color
that text will be rendered on for previews.See also
New in version 3.10.
- Parameters
color (Union[QColor) –
-
setShadow
(self, shadowSettings: QgsTextShadowSettings)¶ Sets the text’s drop shadow settings.
- Parameters
shadowSettings (QgsTextShadowSettings) – shadow settings
See also
-
setSize
(self, size: float)¶ Sets the size for rendered text.
- Parameters
size (float) – size of rendered text. Units are set using setSizeUnit()
See also
See also
-
setSizeMapUnitScale
(self, scale: QgsMapUnitScale)¶ Sets the map unit scale object for the size. This is only used if the sizeUnit() is set to QgsUnitTypes.RenderMapUnit.
See also
See also
- Parameters
scale (QgsMapUnitScale) –
-
setSizeUnit
(self, unit: QgsUnitTypes.RenderUnit)¶ Sets the units for the size of rendered text.
- Parameters
unit (QgsUnitTypes.RenderUnit) – size units
See also
See also
See also
-
shadow
(self) → QgsTextShadowSettings¶ Returns a reference to the text drop shadow settings.
See also
- Return type
-
size
(self) → float¶ Returns the size for rendered text. Units are retrieved using sizeUnit().
See also
See also
- Return type
float
-
sizeMapUnitScale
(self) → QgsMapUnitScale¶ Returns the map unit scale object for the size. This is only used if the sizeUnit() is set to QgsUnitTypes.RenderMapUnit.
See also
See also
- Return type
-
sizeUnit
(self) → QgsUnitTypes.RenderUnit¶ Returns the units for the size of rendered text.
See also
See also
See also
- Return type
-
textFormatPreviewPixmap
(format: QgsTextFormat, size: QSize, previewText: str = '', padding: int = 0) → QPixmap¶ Returns a pixmap preview for a text
format
.- Parameters
format (QgsTextFormat) – text format
size (QSize) – target pixmap size
previewText (str = '') – text to render in preview, or empty for default text
padding (int = 0) – space between icon edge and color ramp
New in version 3.10.
- Return type
QPixmap
-
toMimeData
(self) → QMimeData¶ Returns new mime data representing the text format settings. Caller takes responsibility for deleting the returned object.
See also
- Return type
QMimeData
-
toQFont
(self) → QFont¶ Returns a QFont matching the relevant settings from this text format. Unlike font(), this method also handles the size and size units from the text format.
See also
New in version 3.2.
- Return type
QFont
-
updateDataDefinedProperties
(self, context: QgsRenderContext)¶ Updates the format by evaluating current values of data defined properties.
New in version 3.10.
- Parameters
context (QgsRenderContext) –
-
writeXml
(self, doc: QDomDocument, context: QgsReadWriteContext) → QDomElement¶ Write settings into a DOM element.
See also
- Parameters
doc (QDomDocument) –
context (QgsReadWriteContext) –
- Return type
QDomElement