Class: QgsColorButton¶
- class qgis.gui.QgsColorButton¶
Bases:
PyQt5.QtWidgets.QToolButton
A cross platform button subclass for selecting colors. Will open a color chooser dialog when clicked. Offers live updates to button from color chooser dialog. An attached drop-down menu allows for copying and pasting colors, picking colors from the screen, and selecting colors from color swatch grids.
New in version 2.5.
QgsColorButton(parent: QWidget = None, cdt: str = ‘’, registry:
QgsColorSchemeRegistry
= None) Construct a new color ramp button. Useparent
to attach a parent QWidget to the dialog. Usecdt
string to define the title to show in the color ramp dialog Use a color schemeregistry
for color swatch grids to show in the drop-down menu. If not specified, the button will use the global color scheme registry insteadMethods
Activates the color picker tool, which allows for sampling a color from anywhere on the screen
Returns whether opacity modification (transparency) is permitted for the color.
Returns the behavior for when the button is clicked.
- param e:
Returns the currently selected color.
Returns the title for the color chooser dialog window.
Returns the color scheme registry for the button, which controls the color swatch grids that are shown in the button's drop-down menu.
Returns the context string for the color button.
Copies the current color to the clipboard
Creates an icon for displaying a
color
in a drop-down menu.Returns the default color for the button, which is shown in the button's drop-down menu for the "default color" option.
Reimplemented to accept dragged colors
Reimplemented to reset button appearance after drag leave
Reimplemented to accept dropped colors
- param e:
Returns
True
if the current color is null.Reimplemented to allow canceling color pick via keypress, and sample via space bar press
Sets the button to link to an existing project color, by color
name
.Returns the linked project color name, if set.
- rtype:
QSize
Reimplemented to allow dragging colors from button
Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
Reimplemented to allow color picking
Returns the string used for the "no color" option in the button's drop-down menu.
Pastes a color from the clipboard to the color button.
- param event:
Sets whether opacity modification (transparency) is permitted for the color.
Sets the behavior for when the button is clicked.
Sets the background pixmap for the button based upon color and transparency.
Sets the current color for the button.
Set the title for the color chooser dialog window.
Sets the color scheme registry for the button, which controls the color swatch grids that are shown in the button's drop-down menu.
Sets the context string for the color button.
Sets the default color for the button, which is shown in the button's drop-down menu for the "default color" option.
Sets the string to use for the "no color" option in the button's drop-down menu.
Sets whether the drop-down menu should be shown for the button.
Sets whether the "no color" option should be shown in the button's drop-down menu.
Sets whether a set to null (clear) option is shown in the button's drop-down menu.
Sets color to the button's default color, if set.
Sets color to a totally transparent color.
Sets color to null.
- param e:
Returns whether the drop-down menu is shown for the button.
Returns whether the "no color" option is shown in the button's drop-down menu.
Returns whether the set to null (clear) option is shown in the button's drop-down menu.
- rtype:
QSize
Returns a checkboard pattern pixmap for use as a background to transparent colors
Unlinks the button from a project color.
- param event:
Signals
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
Attributes
- class Behavior¶
Bases:
int
- baseClass¶
alias of
QgsColorButton
- ShowDialog = 0¶
- SignalOnly = 1¶
- actionEvent(self, QActionEvent)¶
- activatePicker(self)¶
Activates the color picker tool, which allows for sampling a color from anywhere on the screen
- allowOpacity(self) bool ¶
Returns whether opacity modification (transparency) is permitted for the color.
- Return type:
bool
- Returns:
True
if opacity modification is allowed
See also
New in version 3.0.
- behavior(self) QgsColorButton.Behavior ¶
Returns the behavior for when the button is clicked.
- Return type:
- Returns:
behavior when button is clicked
See also
- changeEvent(self, e: QEvent)¶
- Parameters:
e (QEvent) –
- checkStateSet(self)¶
- childEvent(self, QChildEvent)¶
- cleared¶
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
- closeEvent(self, QCloseEvent)¶
- color(self) QColor ¶
Returns the currently selected color.
- Return type:
QColor
- Returns:
currently selected color
See also
- colorChanged¶
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
- colorClicked¶
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
- colorDialogTitle(self) str ¶
Returns the title for the color chooser dialog window.
- Return type:
str
- Returns:
title for the color chooser dialog
See also
- colorSchemeRegistry(self) QgsColorSchemeRegistry ¶
Returns the color scheme registry for the button, which controls the color swatch grids that are shown in the button’s drop-down menu.
- Return type:
- Returns:
color scheme registry for the button. If returned value is 0 then all color swatch grids are hidden from the button’s drop-down menu.
See also
- connectNotify(self, QMetaMethod)¶
- context(self) str ¶
Returns the context string for the color button. The context string is passed to all color swatch grids shown in the button’s drop-down menu, to allow them to customize their display colors based on the context.
- Return type:
str
- Returns:
context string for the color button’s color swatch grids
See also
- contextMenuEvent(self, QContextMenuEvent)¶
- copyColor(self)¶
Copies the current color to the clipboard
See also
- create(self, window: PyQt5.sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)¶
- createMenuIcon(color: QColor | Qt.GlobalColor | QGradient, showChecks: bool = True) QPixmap ¶
Creates an icon for displaying a
color
in a drop-down menu.If
showChecks
set toTrue
, then a checkboard pattern will be shown behind semi-transparent colors.New in version 3.6.
- Parameters:
color (Union[QColor) –
showChecks (bool = True) –
- Return type:
QPixmap
- customEvent(self, QEvent)¶
- defaultColor(self) QColor ¶
Returns the default color for the button, which is shown in the button’s drop-down menu for the “default color” option.
- Return type:
QColor
- Returns:
default color for the button. Returns an invalid QColor if the default color option is disabled.
See also
- destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)¶
- disconnectNotify(self, QMetaMethod)¶
- dragEnterEvent(self, e: QDragEnterEvent)¶
Reimplemented to accept dragged colors
- Parameters:
e (QDragEnterEvent) –
- dragLeaveEvent(self, e: QDragLeaveEvent)¶
Reimplemented to reset button appearance after drag leave
- Parameters:
e (QDragLeaveEvent) –
- dragMoveEvent(self, QDragMoveEvent)¶
- dropEvent(self, e: QDropEvent)¶
Reimplemented to accept dropped colors
- 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)¶
- isNull(self) bool ¶
Returns
True
if the current color is null.See also
See also
New in version 2.16.
- Return type:
bool
- isSignalConnected(self, QMetaMethod) bool ¶
- keyPressEvent(self, e: QKeyEvent)¶
Reimplemented to allow canceling color pick via keypress, and sample via space bar press
- Parameters:
e (QKeyEvent) –
- keyReleaseEvent(self, QKeyEvent)¶
- leaveEvent(self, QEvent)¶
- linkToProjectColor(self, name: str)¶
Sets the button to link to an existing project color, by color
name
.This changes the behavior of the button to a “linked” mode. Specifically, the button will show the linked color and respond to changes in the project color scheme by refreshing the displayed color automatically. Additionally, the button’s menu will show items specific to linked color mode, including an option to “unlink” from the project color.
See also
See also
New in version 3.6.
- Parameters:
name (str) –
- linkedProjectColorName(self) str ¶
Returns the linked project color name, if set.
See also
New in version 3.6.
- Return type:
str
- metric(self, QPaintDevice.PaintDeviceMetric) int ¶
- minimumSizeHint(self) QSize ¶
- Return type:
QSize
- mouseDoubleClickEvent(self, QMouseEvent)¶
- mouseMoveEvent(self, e: QMouseEvent)¶
Reimplemented to allow dragging colors from button
- Parameters:
e (QMouseEvent) –
- mousePressEvent(self, e: QMouseEvent)¶
Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
- Parameters:
e (QMouseEvent) –
- mouseReleaseEvent(self, e: QMouseEvent)¶
Reimplemented to allow color picking
- Parameters:
e (QMouseEvent) –
- moveEvent(self, QMoveEvent)¶
- nativeEvent(self, Union[QByteArray, bytes, bytearray], PyQt5.sip.voidptr) Tuple[bool, int] ¶
- nextCheckState(self)¶
- noColorString(self) str ¶
Returns the string used for the “no color” option in the button’s drop-down menu.
- Return type:
str
- Returns:
string used for the “no color” menu option
See also
See also
Note
The “no color” option is only shown if the color button is set to show an alpha channel in the color dialog
- paintEvent(self, QPaintEvent)¶
- pasteColor(self)¶
Pastes a color from the clipboard to the color button. If clipboard does not contain a valid color or string representation of a color, then no change is applied.
See also
- receivers(self, PYQT_SIGNAL) int ¶
- resizeEvent(self, event: QResizeEvent)¶
- Parameters:
event (QResizeEvent) –
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setAllowOpacity(self, allowOpacity: bool)¶
Sets whether opacity modification (transparency) is permitted for the color. Defaults to
False
.- Parameters:
allowOpacity (bool) – set to
True
to allow opacity modification
See also
New in version 3.0.
- setBehavior(self, behavior: QgsColorButton.Behavior)¶
Sets the behavior for when the button is clicked. The default behavior is to show a color picker dialog.
- Parameters:
behavior (QgsColorButton.Behavior) – behavior when button is clicked
See also
- setButtonBackground(self, color: QColor | Qt.GlobalColor | QGradient = QColor())¶
Sets the background pixmap for the button based upon color and transparency. Call directly to update background after adding/removing QColorDialog.ShowAlphaChannel option but the color has not changed, i.e.
setColor()
wouldn’t update button and you want the button to retain the set color’s alpha component regardless- Parameters:
color (Union[QColor) – Color for button background. If no color is specified, the button’s current color will be used
- setColor(self, color: QColor | Qt.GlobalColor | QGradient)¶
Sets the current color for the button. Will emit a colorChanged signal if the color is different to the previous color.
- Parameters:
color (Union[QColor) – new color for the button
See also
- setColorDialogTitle(self, title: str)¶
Set the title for the color chooser dialog window.
- Parameters:
title (str) – Title for the color chooser dialog
See also
- setColorSchemeRegistry(self, registry: QgsColorSchemeRegistry)¶
Sets the color scheme registry for the button, which controls the color swatch grids that are shown in the button’s drop-down menu.
- Parameters:
registry (QgsColorSchemeRegistry) – color scheme registry for the button. Set to 0 to hide all color swatch grids from the button’s drop-down menu.
See also
- setContext(self, context: str)¶
Sets the context string for the color button. The context string is passed to all color swatch grids shown in the button’s drop-down menu, to allow them to customize their display colors based on the context.
- Parameters:
context (str) – context string for the color button’s color swatch grids
See also
- setDefaultColor(self, color: QColor | Qt.GlobalColor | QGradient)¶
Sets the default color for the button, which is shown in the button’s drop-down menu for the “default color” option.
- Parameters:
color (Union[QColor) – default color for the button. Set to an invalid QColor to disable the default color option.
See also
- setNoColorString(self, noColorString: str)¶
Sets the string to use for the “no color” option in the button’s drop-down menu.
- Parameters:
noColorString (str) – string to use for the “no color” menu option
See also
See also
Note
The “no color” option is only shown if the color button is set to show an alpha channel in the color dialog
- setShowMenu(self, showMenu: bool)¶
Sets whether the drop-down menu should be shown for the button. The default behavior is to show the menu.
- Parameters:
showMenu (bool) – set to
False
to hide the drop-down menu
See also
- setShowNoColor(self, showNoColorOption: bool)¶
Sets whether the “no color” option should be shown in the button’s drop-down menu. If selected, the “no color” option sets the color button’s color to a totally transparent color.
- Parameters:
showNoColorOption (bool) – set to
True
to show the no color option. This is disabled by default.
See also
See also
Note
The “no color” option is only shown if the color button is set to show an alpha channel in the color dialog
- setShowNull(self, showNull: bool, nullString: str = '')¶
Sets whether a set to null (clear) option is shown in the button’s drop-down menu.
- Parameters:
showNull (bool) – set to
True
to show a null optionnullString (str = '') – translated string to use for the null option. If not set, a default “Clear Color” string will be used.
See also
See also
New in version 2.16.
- setToDefaultColor(self)¶
Sets color to the button’s default color, if set.
See also
See also
See also
- setToNoColor(self)¶
Sets color to a totally transparent color.
Note
If the color button is not set to show an opacity channel in the color dialog then the color will not be changed.
See also
- setToNull(self)¶
Sets color to null.
See also
See also
See also
New in version 2.16.
- showEvent(self, e: QShowEvent)¶
- Parameters:
e (QShowEvent) –
- showMenu(self) bool ¶
Returns whether the drop-down menu is shown for the button.
- Return type:
bool
- Returns:
True
if drop-down menu is shown
See also
- showNoColor(self) bool ¶
Returns whether the “no color” option is shown in the button’s drop-down menu. If selected, the “no color” option sets the color button’s color to a totally transparent color.
- Return type:
bool
- Returns:
True
if the no color option is shown.
See also
See also
Note
The “no color” option is only shown if the color button is set to show an alpha channel in the color dialog
- showNull(self) bool ¶
Returns whether the set to null (clear) option is shown in the button’s drop-down menu.
See also
See also
New in version 2.16.
- Return type:
bool
- sizeHint(self) QSize ¶
- Return type:
QSize
- tabletEvent(self, QTabletEvent)¶
- timerEvent(self, QTimerEvent)¶
- transparentBackground() QPixmap ¶
Returns a checkboard pattern pixmap for use as a background to transparent colors
- Return type:
QPixmap
- unlink(self)¶
Unlinks the button from a project color.
See also
See also
New in version 3.6.
- unlinked¶
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
- updateMicroFocus(self)¶
- wheelEvent(self, event: QWheelEvent)¶
- Parameters:
event (QWheelEvent) –