QgsFontButton class

A button for customizing QgsTextFormat settings.

The button will open a detailed text format settings dialog when clicked. An attached drop-down menu allows for copying and pasting text styles, picking colors for the text, and for dropping colors from other color widgets.

The button can be used in two different modes(). The default behavior is to include all settings used for configuring QgsTextFormat/QgsTextRenderer classes. A cut down mode (without settings for color) is also available when the resultant font is used only in a QFont object.

Public types

enum Mode { ModeTextRenderer, ModeQFont }
Available button modes.

Constructors, destructors, conversion operators

QgsFontButton(QWidget* parent = nullptr, const QString& dialogTitle = QString())
Construct a new font button.

Public functions

auto currentFont() const -> QFont
Returns the current QFont set by the widget.
auto dialogTitle() const -> QString
Returns the title for the text settings dialog window.
auto mapCanvas() const -> QgsMapCanvas*
Returns the map canvas associated with the widget.
auto mode() const -> QgsFontButton::Mode
Returns the current button mode.
void setDialogTitle(const QString& title)
Sets the title for the text settings dialog window.
void setMapCanvas(QgsMapCanvas* canvas)
Sets a map canvas to associate with the widget.
void setMode(Mode mode)
Sets the current button mode.
auto textFormat() const -> QgsTextFormat
Returns the current text formatting set by the widget.

Signals

void changed()
Emitted when the widget's text format settings are changed.

Public slots

void copyColor()
Copies the current text color to the clipboard.
void copyFormat()
Copies the current text format to the clipboard.
void pasteColor()
Pastes a color from the clipboard to the text format.
void pasteFormat()
Pastes a format from the clipboard.
void setColor(const QColor& color)
Sets the current color for the text.
void setCurrentFont(const QFont& font)
Sets the current text font to show in the widget.
void setTextFormat(const QgsTextFormat& format)
Sets the current text format to show in the widget.

Enum documentation

enum QgsFontButton::Mode

Available button modes.

Enumerators
ModeTextRenderer

Configure font settings for use with QgsTextRenderer.

ModeQFont

Configure font settings for use with QFont objects.

Function documentation

QgsFontButton::QgsFontButton(QWidget* parent = nullptr, const QString& dialogTitle = QString())

Construct a new font button.

Use parent to attach a parent QWidget to the dialog. Use dialogTitle string to define the title to show in the text settings dialog.

QFont QgsFontButton::currentFont() const

Returns the current QFont set by the widget.

This is only used when mode() is ModeQFont.

QString QgsFontButton::dialogTitle() const

Returns the title for the text settings dialog window.

QgsMapCanvas* QgsFontButton::mapCanvas() const

Returns the map canvas associated with the widget.

QgsFontButton::Mode QgsFontButton::mode() const

Returns the current button mode.

void QgsFontButton::setDialogTitle(const QString& title)

Sets the title for the text settings dialog window.

void QgsFontButton::setMapCanvas(QgsMapCanvas* canvas)

Sets a map canvas to associate with the widget.

This allows the widget to fetch current settings from the map canvas, such as current scale.

void QgsFontButton::setMode(Mode mode)

Sets the current button mode.

This can be used to toggle between the full capabilities of the button (for configuring QgsTextFormat/QgsTextRenderer objects) and a cut-back version for configuring QFont object properties (i.e. with no color settings or the other advanced options QgsTextFormat allows).

QgsTextFormat QgsFontButton::textFormat() const

Returns the current text formatting set by the widget.

This is only used when mode() is ModeTextRenderer.

void QgsFontButton::copyColor() public slot

Copies the current text color to the clipboard.

This is only used when mode() is ModeTextRenderer.

void QgsFontButton::copyFormat() public slot

Copies the current text format to the clipboard.

void QgsFontButton::pasteColor() public slot

Pastes a color from the clipboard to the text format.

If clipboard does not contain a valid color or string representation of a color, then no change is applied. This is only used when mode() is ModeTextRenderer.

void QgsFontButton::pasteFormat() public slot

Pastes a format from the clipboard.

If clipboard does not contain a valid format then no change is applied.

void QgsFontButton::setColor(const QColor& color) public slot

Sets the current color for the text.

Will emit a changed signal if the color is different to the previous text color. This is only used when mode() is ModeTextRenderer.

void QgsFontButton::setCurrentFont(const QFont& font) public slot

Sets the current text font to show in the widget.

This is only used when mode() is ModeQFont.

void QgsFontButton::setTextFormat(const QgsTextFormat& format) public slot

Sets the current text format to show in the widget.

This is only used when mode() is ModeTextRenderer.