Class: QgsTextFormatWidget¶
A widget for customizing text formatting settings.
QgsTextFormatWidget
provides a widget for controlling the
appearance of text rendered using QgsTextRenderer
. The
widget includes all settings contained within a
QgsTextFormat
, including shadow, background and buffer.
Additionally, the widget can handle labeling settings due to the large
overlap between the text renderer settings and the labeling settings.
This mode is possible by subclassing QgsTextFormatWidget
and
calling the protected constructor with a mode of Labeling.
Class Hierarchy¶
Base classes¶
Abstract interface for generating an expression context. |
Methods
Returns the context in which the widget is shown, e.g., the associated map canvas and expression contexts. |
|
Deactivate a field from data defined properties and update the corresponding button. |
|
Update the enabled state of the data defined alignment buttons. |
|
Returns the current formatting settings defined by the widget. |
|
Returns the geometry type which will be used by the labeling engine when registering labels for the labeling settings currently defined by the widget. |
|
Sets whether the widget should be shown in a compact dock mode. |
|
Sets the current formatting settings |
|
Sets the background color for the text preview widget. |
|
Toggles whether data defined buttons should be shown in the widget. |
|
Updates line placement options to reflect current state of widget |
|
Updates label placement options to reflect current state of widget |
|
Updates the text preview. |
|
Updates the widget's state to reflect the settings in a |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsTextFormatWidget. See the FAQ for more details.
Saves the current text settings to a style entry. |
|
Sets the context in which the widget is shown, e.g., the associated map canvas and expression contexts. |
|
Sets the current text settings from a style entry. |
Signals
Emitted when an auxiliary field is created in the widget. |
|
Emitted when the text format defined by the widget changes |
Attributes
- class qgis.gui.QgsTextFormatWidget[source]¶
Bases:
QWidget
,QgsExpressionContextGenerator
- __init__(format: QgsTextFormat = QgsTextFormat(), mapCanvas: QgsMapCanvas | None = None, parent: QWidget | None = None, layer: QgsMapLayer | None = None)
Constructor for QgsTextFormatWidget.
- Parameters:
format (
QgsTextFormat
= QgsTextFormat()) – initial formatting settings to show in widgetmapCanvas (Optional[QgsMapCanvas] = None) – associated map canvas
parent (Optional[QWidget] = None) – parent widget
layer (Optional[QgsMapLayer] = None) – associated layer (vector or mesh)
- __init__(mapCanvas: QgsMapCanvas | None, parent: QWidget | None, mode: QgsTextFormatWidget.Mode, layer: QgsMapLayer | None = None)
Constructor for QgsTextFormatWidget.
- Parameters:
mapCanvas (Optional[QgsMapCanvas]) – associated map canvas
parent (Optional[QWidget]) – parent widget
mode (QgsTextFormatWidget.Mode) – widget mode
layer (Optional[QgsMapLayer] = None) – associated vector layer
- Labeling = 1¶
- class Mode¶
Bases:
int
- Text = 0¶
- signal auxiliaryFieldCreated[source]¶
Emitted when an auxiliary field is created in the widget.
Added in version 3.10.
- context(self) QgsSymbolWidgetContext [source]¶
Returns the context in which the widget is shown, e.g., the associated map canvas and expression contexts.
See also
Added in version 3.10.
- Return type:
- deactivateField(self, key: QgsPalLayerSettings.Property)[source]¶
Deactivate a field from data defined properties and update the corresponding button.
- Parameters:
key (QgsPalLayerSettings.Property) – The property key to deactivate
- enableDataDefinedAlignment(self, enable: bool)[source]¶
Update the enabled state of the data defined alignment buttons.
Deprecated since version 3.24.
- Parameters:
enable (bool)
- format(self, includeDataDefinedProperties: bool = True) QgsTextFormat [source]¶
Returns the current formatting settings defined by the widget.
If
includateDataDefinedProperties
isTrue
, then data defined properties specified in the widget will be included in the format definition.- Parameters:
includeDataDefinedProperties (bool = True)
- Return type:
- labelGeometryType(self) Qgis.GeometryType [source]¶
Returns the geometry type which will be used by the labeling engine when registering labels for the labeling settings currently defined by the widget.
Added in version 3.16.
- Return type:
- virtual setContext(self, context: QgsSymbolWidgetContext)[source]¶
Sets the
context
in which the widget is shown, e.g., the associated map canvas and expression contexts.See also
Added in version 3.10.
- Parameters:
context (QgsSymbolWidgetContext)
- setDockMode(self, enabled: bool)[source]¶
Sets whether the widget should be shown in a compact dock mode.
- Parameters:
enabled (bool) – set to
True
to show in dock mode.
- setFormat(self, format: QgsTextFormat)[source]¶
Sets the current formatting settings
Added in version 3.2.
- Parameters:
format (QgsTextFormat)
- virtual setFormatFromStyle(self, name: str | None, type: QgsStyle.StyleEntity, stylePath: str | None)[source]¶
Sets the current text settings from a style entry.
Added in version 3.10.
- Parameters:
name (Optional[str])
type (QgsStyle.StyleEntity)
stylePath (Optional[str])
- setPreviewBackground(self, color: QColor | Qt.GlobalColor)[source]¶
Sets the background color for the text preview widget.
- Parameters:
color (Union[QColor, Qt.GlobalColor]) – background color
- setPropertyOverrideButtonsVisible(self, visible: bool)[source]¶
Toggles whether data defined buttons should be shown in the widget.
Added in version 3.42.
- Parameters:
visible (bool)
- updateLinePlacementOptions(self)[source]¶
Updates line placement options to reflect current state of widget
- updatePlacementWidgets(self)[source]¶
Updates label placement options to reflect current state of widget
- updateWidgetForFormat(self, format: QgsTextFormat)[source]¶
Updates the widget’s state to reflect the settings in a
QgsTextFormat
.- Parameters:
format (QgsTextFormat) – source format