Class: QgsFontButton

class qgis.gui.QgsFontButton(parent: QWidget = None, dialogTitle: str = '')

Bases: PyQt5.QtWidgets.QToolButton

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.

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.

New in version 3.0: Enums

Methods

actionEvent

changeEvent

checkStateSet

childEvent

closeEvent

connectNotify

contextMenuEvent

copyColor

Copies the current text color to the clipboard.

copyFormat

Copies the current text format to the clipboard.

create

currentFont

Returns the current QFont set by the widget.

customEvent

destroy

dialogTitle

Returns the title for the text settings dialog window.

disconnectNotify

dragEnterEvent

dragLeaveEvent

dragMoveEvent

dropEvent

enterEvent

event

focusInEvent

focusNextChild

focusNextPrevChild

focusOutEvent

focusPreviousChild

hideEvent

hitButton

initPainter

initStyleOption

inputMethodEvent

isSignalConnected

keyPressEvent

keyReleaseEvent

layer

Returns the layer associated with the widget.

leaveEvent

mapCanvas

Returns the map canvas associated with the widget.

messageBar

Returns the message bar associated with the widget.

metric

minimumSizeHint

mode

Returns the current button mode.

mouseDoubleClickEvent

mouseMoveEvent

mousePressEvent

mouseReleaseEvent

moveEvent

nativeEvent

nextCheckState

paintEvent

pasteColor

Pastes a color from the clipboard to the text format.

pasteFormat

Pastes a format from the clipboard.

receivers

registerExpressionContextGenerator

Register an expression context generator class that will be used to retrieve an expression context for the button when required.

resizeEvent

sender

senderSignalIndex

setColor

Sets the current color for the text.

setCurrentFont

Sets the current text font to show in the widget.

setDialogTitle

Sets the title for the text settings dialog window.

setLayer

Sets a layer to associate with the widget.

setMapCanvas

Sets a map canvas to associate with the widget.

setMessageBar

Sets the message bar associated with the widget.

setMode

Sets the current button mode.

setTextFormat

Sets the current text format to show in the widget.

sharedPainter

showEvent

sizeHint

tabletEvent

textFormat

Returns the current text formatting set by the widget.

timerEvent

updateMicroFocus

wheelEvent

Signals

changed

Emitted when the widget’s text format settings are changed.

Attributes

ModeQFont

ModeTextRenderer

class Mode

Bases: int

baseClass

alias of QgsFontButton

ModeQFont = 1
ModeTextRenderer = 0
actionEvent()
changeEvent(self, e: QEvent)
changed

Emitted when the widget’s text format settings are changed. [signal]

checkStateSet()
childEvent()
closeEvent()
connectNotify()
contextMenuEvent()
copyColor(self)

Copies the current text color to the clipboard. This is only used when mode() is ModeTextRenderer.

See also

pasteColor()

copyFormat(self)

Copies the current text format to the clipboard.

See also

pasteFormat()

create()
currentFont(self) → QFont

Returns the current QFont set by the widget. This is only used when mode() is ModeQFont.

See also

setCurrentFont()

customEvent()
destroy()
dialogTitle(self) → str

Returns the title for the text settings dialog window.

See also

setDialogTitle()

disconnectNotify()
dragEnterEvent(self, e: QDragEnterEvent)
dragLeaveEvent(self, e: QDragLeaveEvent)
dragMoveEvent()
dropEvent(self, e: QDropEvent)
enterEvent()
event(self, e: QEvent) → bool
focusInEvent()
focusNextChild()
focusNextPrevChild()
focusOutEvent()
focusPreviousChild()
hideEvent()
hitButton()
initPainter()
initStyleOption()
inputMethodEvent()
isSignalConnected()
keyPressEvent()
keyReleaseEvent()
layer(self) → QgsVectorLayer

Returns the layer associated with the widget.

See also

setLayer()

New in version 3.10.

leaveEvent()
mapCanvas(self) → QgsMapCanvas

Returns the map canvas associated with the widget.

See also

setMapCanvas()

messageBar(self) → QgsMessageBar

Returns the message bar associated with the widget.

See also

setMessageBar()

New in version 3.10.

metric()
minimumSizeHint(self) → QSize
mode(self) → QgsFontButton.Mode

Returns the current button mode.

See also

setMode()

mouseDoubleClickEvent()
mouseMoveEvent(self, e: QMouseEvent)
mousePressEvent(self, e: QMouseEvent)
mouseReleaseEvent()
moveEvent()
nativeEvent()
nextCheckState()
paintEvent()
pasteColor(self)

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.

See also

copyColor()

pasteFormat(self)

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

See also

copyFormat()

receivers()
registerExpressionContextGenerator(self, generator: QgsExpressionContextGenerator)

Register an expression context generator class that will be used to retrieve an expression context for the button when required.

New in version 3.10.

resizeEvent(self, event: QResizeEvent)
sender()
senderSignalIndex()
setColor(self, color: Union[QColor, Qt.GlobalColor, QGradient])

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.

setCurrentFont(self, font: QFont)

Sets the current text font to show in the widget. This is only used when mode() is ModeQFont.

See also

currentFont()

setDialogTitle(self, title: str)

Sets the title for the text settings dialog window.

See also

dialogTitle()

setLayer(self, layer: QgsVectorLayer)

Sets a layer to associate with the widget. This allows the widget to setup layer related settings within the text settings dialog, such as correctly populating data defined override buttons.

See also

layer()

New in version 3.10.

setMapCanvas(self, canvas: QgsMapCanvas)

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.

See also

mapCanvas()

setMessageBar(self, bar: QgsMessageBar)

Sets the message bar associated with the widget. This allows the widget to push feedback messages to the appropriate message bar.

See also

messageBar()

New in version 3.10.

setMode(self, mode: QgsFontButton.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).

See also

mode()

setTextFormat(self, format: QgsTextFormat)

Sets the current text format to show in the widget. This is only used when mode() is ModeTextRenderer.

See also

textFormat()

sharedPainter()
showEvent(self, e: QShowEvent)
sizeHint(self) → QSize
tabletEvent()
textFormat(self) → QgsTextFormat

Returns the current text formatting set by the widget. This is only used when mode() is ModeTextRenderer.

See also

setTextFormat()

timerEvent()
updateMicroFocus()
wheelEvent(self, event: QWheelEvent)