Class: QgsTextFormatWidget

class qgis.gui.QgsTextFormatWidget(format: QgsTextFormat = QgsTextFormat(), mapCanvas: QgsMapCanvas = None, parent: QWidget = None, layer: QgsVectorLayer = None)

Bases: PyQt5.QtWidgets.QWidget, qgis._core.QgsExpressionContextGenerator

Constructor for QgsTextFormatWidget.

Parameters
  • format – initial formatting settings to show in widget

  • mapCanvas – associated map canvas

  • parent – parent widget

  • layer – associated vector layer

QgsTextFormatWidget(mapCanvas: QgsMapCanvas, parent: QWidget, mode: QgsTextFormatWidget.Mode, layer: QgsVectorLayer = None) Constructor for QgsTextFormatWidget.

Parameters
  • mapCanvas – associated map canvas

  • parent – parent widget

  • mode – widget mode

  • layer – associated vector layer

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.

New in version 3.0: Enums

Methods

actionEvent

changeEvent

childEvent

closeEvent

connectNotify

context

Returns the context in which the widget is shown, e.g., the associated map canvas and expression contexts.

contextMenuEvent

create

createExpressionContext

customEvent

deactivateField

Deactivate a field from data defined properties and update the corresponding button.

destroy

disconnectNotify

dragEnterEvent

dragLeaveEvent

dragMoveEvent

dropEvent

enableDataDefinedAlignment

Controls whether data defined alignment buttons are enabled.

enterEvent

event

focusInEvent

focusNextChild

focusNextPrevChild

focusOutEvent

focusPreviousChild

format

Returns the current formatting settings defined by the widget.

hideEvent

initPainter

inputMethodEvent

isSignalConnected

keyPressEvent

keyReleaseEvent

leaveEvent

metric

mouseDoubleClickEvent

mouseMoveEvent

mousePressEvent

mouseReleaseEvent

moveEvent

nativeEvent

paintEvent

receivers

resizeEvent

saveFormat

Saves the current text settings to a style entry.

sender

senderSignalIndex

setContext

Sets the context in which the widget is shown, e.g., the associated map canvas and expression contexts.

setDockMode

Sets whether the widget should be shown in a compact dock mode.

setFormat

Sets the current formatting settings

setFormatFromStyle

Sets the current text settings from a style entry.

setPreviewBackground

Sets the background color for the text preview widget.

sharedPainter

showEvent

tabletEvent

timerEvent

updateLinePlacementOptions

Updates line placement options to reflect current state of widget

updateMicroFocus

updatePlacementWidgets

Updates label placement options to reflect current state of widget

updatePreview

Updates the text preview.

updateWidgetForFormat

Updates the widget’s state to reflect the settings in a QgsTextFormat.

wheelEvent

Signals

auxiliaryFieldCreated

Emitted when an auxiliary field is creatd in the widget.

widgetChanged

Emitted when the text format defined by the widget changes [signal]

Attributes

Labeling

Text

Labeling = 1
class Mode

Bases: int

Text = 0
actionEvent()
auxiliaryFieldCreated

Emitted when an auxiliary field is creatd in the widget.

New in version 3.10: [signal]

changeEvent()
childEvent()
closeEvent()
connectNotify()
context(self) → QgsSymbolWidgetContext

Returns the context in which the widget is shown, e.g., the associated map canvas and expression contexts.

See also

setContext()

New in version 3.10.

contextMenuEvent()
create()
createExpressionContext(self) → QgsExpressionContext
customEvent()
deactivateField(self, key: QgsPalLayerSettings.Property)

Deactivate a field from data defined properties and update the corresponding button.

Parameters

key – The property key to deactivate

New in version 3.0.

destroy()
disconnectNotify()
dragEnterEvent()
dragLeaveEvent()
dragMoveEvent()
dropEvent()
enableDataDefinedAlignment(self, enable: bool)

Controls whether data defined alignment buttons are enabled.

Parameters

enable – set to True to enable alignment controls

enterEvent()
event()
focusInEvent()
focusNextChild()
focusNextPrevChild()
focusOutEvent()
focusPreviousChild()
format(self, includeDataDefinedProperties: bool = True) → QgsTextFormat

Returns the current formatting settings defined by the widget.

If includateDataDefinedProperties is True, then data defined properties specified in the widget will be included in the format definition.

hideEvent()
initPainter()
inputMethodEvent()
isSignalConnected()
keyPressEvent()
keyReleaseEvent()
leaveEvent()
metric()
mouseDoubleClickEvent()
mouseMoveEvent()
mousePressEvent()
mouseReleaseEvent()
moveEvent()
nativeEvent()
paintEvent()
receivers()
resizeEvent()
saveFormat(self)

Saves the current text settings to a style entry.

sender()
senderSignalIndex()
setContext(self, context: QgsSymbolWidgetContext)

Sets the context in which the widget is shown, e.g., the associated map canvas and expression contexts.

See also

context()

New in version 3.10.

setDockMode(self, enabled: bool)

Sets whether the widget should be shown in a compact dock mode.

Parameters

enabled – set to True to show in dock mode.

setFormat(self, format: QgsTextFormat)

Sets the current formatting settings

New in version 3.2.

setFormatFromStyle(self, name: str, type: QgsStyle.StyleEntity)

Sets the current text settings from a style entry.

New in version 3.10.

setPreviewBackground(self, color: Union[QColor, Qt.GlobalColor, QGradient])

Sets the background color for the text preview widget.

Parameters

color – background color

sharedPainter()
showEvent()
tabletEvent()
timerEvent()
updateLinePlacementOptions(self)

Updates line placement options to reflect current state of widget

updateMicroFocus()
updatePlacementWidgets(self)

Updates label placement options to reflect current state of widget

updatePreview(self)

Updates the text preview.

New in version 3.10.

updateWidgetForFormat(self, format: QgsTextFormat)

Updates the widget’s state to reflect the settings in a QgsTextFormat.

Parameters

format – source format

wheelEvent()
widgetChanged

Emitted when the text format defined by the widget changes [signal]