Class: QgsFontButton¶
- class qgis.gui.QgsFontButton¶
Bases:
PyQt5.QtWidgets.QToolButton
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 configuringQgsTextFormat
/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.
QgsFontButton(parent: QWidget = None, dialogTitle: str = ‘’) Construct a new font button. Use
parent
to attach a parent QWidget to the dialog. UsedialogTitle
string to define the title to show in the text settings dialog.Methods
- param e:
Copies the current text color to the clipboard.
Copies the current text format to the clipboard.
Returns the current QFont set by the widget.
Returns the title for the text settings dialog window.
- param e:
- param e:
- param e:
- param e:
Returns the layer associated with the widget.
Returns the map canvas associated with the widget.
Returns the message bar associated with the widget.
- rtype:
QSize
Returns the current button mode.
- param e:
- param e:
Pastes a color from the clipboard to the text format.
Pastes a format from the clipboard.
Register an expression context generator class that will be used to retrieve an expression context for the button when required.
- param event:
Sets the current
color
for the text.Sets the current text
font
to show in the widget.Sets the
title
for the text settings dialog window.Sets a
layer
to associate with the widget.Sets a map
canvas
to associate with the widget.Sets the message
bar
associated with the widget.Sets the current button
mode
.Sets the
string
to use for the "null format" option in the button's drop-down menu.Sets whether the "null format" option should be shown in the button's drop-down menu.
Sets the current text
format
to show in the widget.Sets the text format to a null (invalid)
QgsTextFormat
.- param e:
Returns whether the "null format" option will be shown in the button's drop-down menu.
- rtype:
QSize
Returns the current text formatting set by the widget.
- param event:
Signals
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
Attributes
- class Mode¶
Bases:
int
- baseClass¶
alias of
QgsFontButton
- ModeQFont = 1¶
- ModeTextRenderer = 0¶
- actionEvent(self, QActionEvent)¶
- changeEvent(self, e: QEvent)¶
- Parameters:
e (QEvent) –
- changed¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- checkStateSet(self)¶
- childEvent(self, QChildEvent)¶
- closeEvent(self, QCloseEvent)¶
- connectNotify(self, QMetaMethod)¶
- contextMenuEvent(self, QContextMenuEvent)¶
- copyColor(self)¶
Copies the current text color to the clipboard. This is only used when
mode()
is ModeTextRenderer.See also
- copyFormat(self)¶
Copies the current text format to the clipboard.
See also
- create(self, window: PyQt5.sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)¶
- currentFont(self) QFont ¶
Returns the current QFont set by the widget. This is only used when
mode()
is ModeQFont.See also
- Return type:
QFont
- customEvent(self, QEvent)¶
- destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)¶
- dialogTitle(self) str ¶
Returns the title for the text settings dialog window.
See also
- Return type:
str
- disconnectNotify(self, QMetaMethod)¶
- dragEnterEvent(self, e: QDragEnterEvent)¶
- Parameters:
e (QDragEnterEvent) –
- dragLeaveEvent(self, e: QDragLeaveEvent)¶
- Parameters:
e (QDragLeaveEvent) –
- dragMoveEvent(self, QDragMoveEvent)¶
- dropEvent(self, e: QDropEvent)¶
- Parameters:
e (QDropEvent) –
- enterEvent(self, QEvent)¶
- event(self, e: QEvent) bool ¶
- Parameters:
e (QEvent) –
- Return type:
bool
- focusInEvent(self, QFocusEvent)¶
- focusNextChild(self) bool ¶
- focusNextPrevChild(self, bool) bool ¶
- focusOutEvent(self, QFocusEvent)¶
- focusPreviousChild(self) bool ¶
- hideEvent(self, QHideEvent)¶
- hitButton(self, QPoint) bool ¶
- initPainter(self, QPainter)¶
- initStyleOption(self, QStyleOptionToolButton)¶
- inputMethodEvent(self, QInputMethodEvent)¶
- isSignalConnected(self, QMetaMethod) bool ¶
- keyPressEvent(self, QKeyEvent)¶
- keyReleaseEvent(self, QKeyEvent)¶
- layer(self) QgsVectorLayer ¶
Returns the layer associated with the widget.
See also
New in version 3.10.
- Return type:
- leaveEvent(self, QEvent)¶
- mapCanvas(self) QgsMapCanvas ¶
Returns the map canvas associated with the widget.
See also
- Return type:
- messageBar(self) QgsMessageBar ¶
Returns the message bar associated with the widget.
See also
New in version 3.10.
- Return type:
- metric(self, QPaintDevice.PaintDeviceMetric) int ¶
- minimumSizeHint(self) QSize ¶
- Return type:
QSize
- mode(self) QgsFontButton.Mode ¶
Returns the current button mode.
See also
- Return type:
- mouseDoubleClickEvent(self, QMouseEvent)¶
- mouseMoveEvent(self, e: QMouseEvent)¶
- Parameters:
e (QMouseEvent) –
- mousePressEvent(self, e: QMouseEvent)¶
- Parameters:
e (QMouseEvent) –
- mouseReleaseEvent(self, QMouseEvent)¶
- moveEvent(self, QMoveEvent)¶
- nativeEvent(self, Union[QByteArray, bytes, bytearray], PyQt5.sip.voidptr) Tuple[bool, int] ¶
- nextCheckState(self)¶
- paintEvent(self, QPaintEvent)¶
- 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
- pasteFormat(self)¶
Pastes a format from the clipboard. If clipboard does not contain a valid format then no change is applied.
See also
- receivers(self, PYQT_SIGNAL) int ¶
- 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.
- Parameters:
generator (QgsExpressionContextGenerator) –
- resizeEvent(self, event: QResizeEvent)¶
- Parameters:
event (QResizeEvent) –
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setColor(self, color: 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 whenmode()
is ModeTextRenderer.- Parameters:
color (Union[QColor) –
- setCurrentFont(self, font: QFont)¶
Sets the current text
font
to show in the widget. This is only used whenmode()
is ModeQFont.See also
- Parameters:
font (QFont) –
- setDialogTitle(self, title: str)¶
Sets the
title
for the text settings dialog window.See also
- Parameters:
title (str) –
- 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
New in version 3.10.
- Parameters:
layer (QgsVectorLayer) –
- 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
- Parameters:
canvas (QgsMapCanvas) –
- 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
New in version 3.10.
- Parameters:
bar (QgsMessageBar) –
- setMode(self, mode: QgsFontButton.Mode)¶
Sets the current button
mode
. This can be used to toggle between the full capabilities of the button (for configuringQgsTextFormat
/QgsTextRenderer
objects) and a cut-back version for configuring QFont object properties (i.e. with no color settings or the other advanced optionsQgsTextFormat
allows).See also
- Parameters:
mode (QgsFontButton.Mode) –
- setNoFormatString(self, string: str)¶
Sets the
string
to use for the “null format” option in the button’s drop-down menu.Note
The “null format” option is only shown if
showNullFormat()
isTrue
.See also
New in version 3.16.
- Parameters:
string (str) –
- setShowNullFormat(self, show: bool)¶
Sets whether the “null format” option should be shown in the button’s drop-down menu. This option is only used for buttons set to the ModeTextRenderer
mode()
.If selected, the “null format” option sets the button’s format to an invalid
QgsTextFormat
. This can be used to represent a “use default format” state for the button.By default this option is not shown.
See also
See also
New in version 3.16.
- Parameters:
show (bool) –
- setTextFormat(self, format: QgsTextFormat)¶
Sets the current text
format
to show in the widget. This is only used whenmode()
is ModeTextRenderer.See also
- Parameters:
format (QgsTextFormat) –
- setToNullFormat(self)¶
Sets the text format to a null (invalid)
QgsTextFormat
.This is only used when
mode()
is ModeTextRenderer.New in version 3.16.
- showEvent(self, e: QShowEvent)¶
- Parameters:
e (QShowEvent) –
- showNullFormat(self) bool ¶
Returns whether the “null format” option will be shown in the button’s drop-down menu. This option is only used for buttons set to the ModeTextRenderer
mode()
.If selected, the “null format” option sets the button’s format to an invalid
QgsTextFormat
. This can be used to represent a “use default format” state for the button.By default this option is not shown.
See also
New in version 3.16.
- Return type:
bool
- sizeHint(self) QSize ¶
- Return type:
QSize
- tabletEvent(self, QTabletEvent)¶
- textFormat(self) QgsTextFormat ¶
Returns the current text formatting set by the widget. This is only used when
mode()
is ModeTextRenderer.See also
- Return type:
- timerEvent(self, QTimerEvent)¶
- updateMicroFocus(self)¶
- wheelEvent(self, event: QWheelEvent)¶
- Parameters:
event (QWheelEvent) –