QgsTextFormatWidget class

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.

Constructors, destructors, conversion operators

QgsTextFormatWidget(const QgsTextFormat& format = QgsTextFormat(), QgsMapCanvas* mapCanvas = nullptr, QWidget* parent = nullptr)
Constructor for QgsTextFormatWidget.
QgsTextFormatWidget(QgsMapCanvas* mapCanvas, QWidget* parent, Mode mode) protected
Constructor for QgsTextFormatWidget.

Public functions

auto format() const -> QgsTextFormat
Returns the current formatting settings defined by the widget.
void setFormat(const QgsTextFormat& format)
Sets the current formatting settings.

Signals

void widgetChanged()
Emitted when the text format defined by the widget changes.

Public slots

void setDockMode(bool enabled)
Sets whether the widget should be shown in a compact dock mode.

Protected types

enum Mode { Text = 0, Labeling }
Widget mode.

Protected functions

void enableDataDefinedAlignment(bool enable)
Controls whether data defined alignment buttons are enabled.
void setPreviewBackground(const QColor& color)
Sets the background color for the text preview widget.
void updateWidgetForFormat(const QgsTextFormat& format)
Updates the widget's state to reflect the settings in a QgsTextFormat.

Protected slots

void updateLinePlacementOptions()
Updates line placement options to reflect current state of widget.
void updatePlacementWidgets()
Updates label placement options to reflect current state of widget.

Protected variables

QButtonGroup* mDirectSymbBtnGrp
Symbol direction button group.
int mMinPixelLimit
Pixel size font limit.
QButtonGroup* mPlaceLineBtnGrp
Line placement button group.
QButtonGroup* mPlacePointBtnGrp
Point placement button group.
QButtonGroup* mPlacePolygonBtnGrp
Polygon placement button group.
QButtonGroup* mQuadrantBtnGrp
Quadrant button group.
QgsStringReplacementCollection mSubstitutions
Text substitution list.
QButtonGroup* mUpsidedownBtnGrp
Upside down labels button group.

Enum documentation

enum QgsTextFormatWidget::Mode protected

Widget mode.

Enumerators
Text

Default mode, show text formatting settings only.

Labeling

Show labeling settings in addition to text formatting settings.

Function documentation

QgsTextFormatWidget::QgsTextFormatWidget(const QgsTextFormat& format = QgsTextFormat(), QgsMapCanvas* mapCanvas = nullptr, QWidget* parent = nullptr)

Constructor for QgsTextFormatWidget.

Parameters
format initial formatting settings to show in widget
mapCanvas associated map canvas
parent parent widget

QgsTextFormatWidget::QgsTextFormatWidget(QgsMapCanvas* mapCanvas, QWidget* parent, Mode mode) protected

Constructor for QgsTextFormatWidget.

Parameters
mapCanvas associated map canvas
parent parent widget
mode widget mode

void QgsTextFormatWidget::setFormat(const QgsTextFormat& format)

Sets the current formatting settings.

void QgsTextFormatWidget::setDockMode(bool enabled) public slot

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

Parameters
enabled set to true to show in dock mode.

void QgsTextFormatWidget::enableDataDefinedAlignment(bool enable) protected

Controls whether data defined alignment buttons are enabled.

Parameters
enable set to true to enable alignment controls

void QgsTextFormatWidget::setPreviewBackground(const QColor& color) protected

Sets the background color for the text preview widget.

Parameters
color background color

void QgsTextFormatWidget::updateWidgetForFormat(const QgsTextFormat& format) protected

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

Parameters
format source format