Subgroup: Color
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: Methods
acceptDrops
acceptLiveUpdates
Returns whether the button accepts live updates from QColorDialog. accessibleDescription
accessibleName
actionEvent
actions
activatePicker
Activates the color picker tool, which allows for sampling a color from anywhere on the screen activateWindow
addAction
addActions
adjustSize
allowOpacity
Returns whether opacity modification (transparency) is permitted for the color. animateClick
arrowType
autoExclusive
autoFillBackground
autoRaise
autoRepeat
autoRepeatDelay
autoRepeatInterval
backgroundRole
baseSize
behavior
Returns the behavior for when the button is clicked. blockSignals
changeEvent
checkStateSet
childAt
childAt(self, int, int) -> QWidget childEvent
children
childrenRect
childrenRegion
clearFocus
clearMask
click
close
closeEvent
color
Return the currently selected color. colorCount
colorDialogTitle
Returns the title for the color chooser dialog window. colorSchemeRegistry
Returns the color scheme registry for the button, which controls the color swatch grids that are shown in the button’s drop-down menu. connectNotify
contentsMargins
contentsRect
context
Returns the context string for the color button. contextMenuEvent
contextMenuPolicy
copyColor
Copies the current color to the clipboard create
createWindowContainer
cursor
customEvent
defaultAction
defaultColor
Returns the default color for the button, which is shown in the button’s drop-down menu for the “default color” option. deleteLater
depth
destroy
devType
devicePixelRatio
devicePixelRatioF
devicePixelRatioFScale
disconnect
disconnectNotify
dragEnterEvent
Reimplemented to accept dragged colors dragLeaveEvent
Reimplemented to reset button appearance after drag leave dragMoveEvent
dropEvent
Reimplemented to accept dropped colors dumpObjectInfo
dumpObjectTree
dynamicPropertyNames
effectiveWinId
ensurePolished
enterEvent
event
eventFilter
find
findChild
findChild(self, Tuple, name: str = ‘’, options: Union[Qt.FindChildOptions, Qt.FindChildOption] = Qt.FindChildrenRecursively) -> QObject findChildren
findChildren(self, Tuple, name: str = ‘’, options: Union[Qt.FindChildOptions, Qt.FindChildOption] = Qt.FindChildrenRecursively) -> List[QObject] focusInEvent
focusNextChild
focusNextPrevChild
focusOutEvent
focusPolicy
focusPreviousChild
focusProxy
focusWidget
font
fontInfo
fontMetrics
foregroundRole
frameGeometry
frameSize
geometry
getContentsMargins
grab
grabGesture
grabKeyboard
grabMouse
grabMouse(self, Union[QCursor, Qt.CursorShape]) grabShortcut
graphicsEffect
graphicsProxyWidget
group
hasFocus
hasHeightForWidth
hasMouseTracking
hasTabletTracking
height
heightForWidth
heightMM
hide
hideEvent
hitButton
icon
iconSize
inherits
initPainter
initStyleOption
inputMethodEvent
inputMethodHints
inputMethodQuery
insertAction
insertActions
installEventFilter
isActiveWindow
isAncestorOf
isCheckable
isChecked
isDown
isEnabled
isEnabledTo
isFullScreen
isHidden
isLeftToRight
isMaximized
isMinimized
isModal
isNull
Returns true if the current color is null. isRightToLeft
isSignalConnected
isVisible
isVisibleTo
isWidgetType
isWindow
isWindowModified
isWindowType
keyPressEvent
Reimplemented to allow canceling color pick via keypress, and sample via space bar press keyReleaseEvent
keyboardGrabber
killTimer
layout
layoutDirection
leaveEvent
locale
logicalDpiX
logicalDpiY
lower
mapFrom
mapFromGlobal
mapFromParent
mapTo
mapToGlobal
mapToParent
mask
maximumHeight
maximumSize
maximumWidth
menu
metaObject
metric
minimumHeight
minimumSize
minimumSizeHint
minimumWidth
mouseDoubleClickEvent
mouseGrabber
mouseMoveEvent
Reimplemented to allow dragging colors from button mousePressEvent
Reimplemented to detect right mouse button clicks on the color button and allow dragging colors mouseReleaseEvent
Reimplemented to allow color picking move
move(self, int, int) moveEvent
moveToThread
nativeEvent
nativeParentWidget
nextCheckState
nextInFocusChain
noColorString
Returns the string used for the “no color” option in the button’s drop-down menu. normalGeometry
objectName
overrideWindowFlags
overrideWindowState
paintEngine
paintEvent
paintingActive
palette
parent
parentWidget
pasteColor
Pastes a color from the clipboard to the color button. physicalDpiX
physicalDpiY
popupMode
pos
previousInFocusChain
property
pyqtConfigure
Each keyword argument is either the name of a Qt property or a Qt signal. raise_
receivers
rect
releaseKeyboard
releaseMouse
releaseShortcut
removeAction
removeEventFilter
render
render(self, QPainter, targetOffset: QPoint = QPoint(), sourceRegion: QRegion = QRegion(), flags: Union[QWidget.RenderFlags, QWidget.RenderFlag] = QWidget.RenderFlags(QWidget.DrawWindowBackground|QWidget.DrawChildren)) repaint
repaint(self, int, int, int, int) resize
resize(self, int, int) resizeEvent
restoreGeometry
saveGeometry
scroll
scroll(self, int, int, QRect) sender
senderSignalIndex
setAcceptDrops
setAcceptLiveUpdates
Sets whether the button accepts live updates from QColorDialog. setAccessibleDescription
setAccessibleName
setAllowOpacity
Sets whether opacity modification (transparency) is permitted for the color. setArrowType
setAttribute
setAutoExclusive
setAutoFillBackground
setAutoRaise
setAutoRepeat
setAutoRepeatDelay
setAutoRepeatInterval
setBackgroundRole
setBaseSize
setBaseSize(self, QSize) setBehavior
Sets the behavior for when the button is clicked. setButtonBackground
Sets the background pixmap for the button based upon color and transparency. setCheckable
setChecked
setColor
Sets the current color for the button. setColorDialogTitle
Set the title for the color chooser dialog window. setColorSchemeRegistry
Sets the color scheme registry for the button, which controls the color swatch grids that are shown in the button’s drop-down menu. setContentsMargins
setContentsMargins(self, QMargins) setContext
Sets the context string for the color button. setContextMenuPolicy
setCursor
setDefaultAction
setDefaultColor
Sets the default color for the button, which is shown in the button’s drop-down menu for the “default color” option. setDisabled
setDown
setEnabled
setFixedHeight
setFixedSize
setFixedSize(self, int, int) setFixedWidth
setFocus
setFocus(self, Qt.FocusReason) setFocusPolicy
setFocusProxy
setFont
setForegroundRole
setGeometry
setGeometry(self, int, int, int, int) setGraphicsEffect
setHidden
setIcon
setIconSize
setInputMethodHints
setLayout
setLayoutDirection
setLocale
setMask
setMask(self, QRegion) setMaximumHeight
setMaximumSize
setMaximumSize(self, QSize) setMaximumWidth
setMenu
setMinimumHeight
setMinimumSize
setMinimumSize(self, QSize) setMinimumWidth
setMouseTracking
setNoColorString
Sets the string to use for the “no color” option in the button’s drop-down menu. setObjectName
setPalette
setParent
setParent(self, QWidget, Union[Qt.WindowFlags, Qt.WindowType]) setPopupMode
setProperty
setShortcut
setShortcutAutoRepeat
setShortcutEnabled
setShowMenu
Sets whether the drop-down menu should be shown for the button. setShowNoColor
Sets whether the “no color” option should be shown in the button’s drop-down menu. setShowNull
Sets whether a set to null (clear) option is shown in the button’s drop-down menu. setSizeIncrement
setSizeIncrement(self, QSize) setSizePolicy
setSizePolicy(self, QSizePolicy.Policy, QSizePolicy.Policy) setStatusTip
setStyle
setStyleSheet
setTabOrder
setTabletTracking
setText
setToDefaultColor
Sets color to the button’s default color, if set. setToNoColor
Sets color to a totally transparent color. setToNull
Sets color to null. setToolButtonStyle
setToolTip
setToolTipDuration
setUpdatesEnabled
setVisible
setWhatsThis
setWindowFilePath
setWindowFlag
setWindowFlags
setWindowIcon
setWindowIconText
setWindowModality
setWindowModified
setWindowOpacity
setWindowRole
setWindowState
setWindowTitle
sharedPainter
shortcut
show
showEvent
showFullScreen
showMaximized
showMenu
Returns whether the drop-down menu is shown for the button. showMinimized
showNoColor
Returns whether the “no color” option is shown in the button’s drop-down menu. showNormal
showNull
Returns whether the set to null (clear) option is shown in the button’s drop-down menu. signalsBlocked
size
sizeHint
sizeIncrement
sizePolicy
stackUnder
startTimer
statusTip
style
styleSheet
tabletEvent
testAttribute
text
thread
timerEvent
toggle
toolButtonStyle
toolTip
toolTipDuration
tr
transparentBackground
Returns a checkboard pattern pixmap for use as a background to transparent colors underMouse
ungrabGesture
unsetCursor
unsetLayoutDirection
unsetLocale
update
update(self, QRect) updateGeometry
updateMicroFocus
updatesEnabled
visibleRegion
whatsThis
wheelEvent
width
widthMM
winId
window
windowFilePath
windowFlags
windowHandle
windowIcon
windowIconText
windowModality
windowOpacity
windowRole
windowState
windowTitle
windowType
x
y
Attributes
DelayedPopup
DrawChildren
DrawWindowBackground
IgnoreMask
InstantPopup
MenuButtonPopup
PdmDepth
PdmDevicePixelRatio
PdmDevicePixelRatioScaled
PdmDpiX
PdmDpiY
PdmHeight
PdmHeightMM
PdmNumColors
PdmPhysicalDpiX
PdmPhysicalDpiY
PdmWidth
PdmWidthMM
ShowDialog
SignalOnly
clicked
clicked(self, bool = False) [signal] colorChanged
Is emitted whenever a new color is set for the button. colorClicked
Emitted when the button is clicked, if the button’s behavior is set to SignalOnly customContextMenuRequested
customContextMenuRequested(self, QPoint) [signal] destroyed
destroyed(self, QObject = None) [signal] objectNameChanged
objectNameChanged(self, str) [signal] pressed
pressed(self) [signal] released
released(self) [signal] staticMetaObject
toggled
toggled(self, bool) [signal] triggered
triggered(self, QAction) [signal] windowIconChanged
windowIconChanged(self, QIcon) [signal] windowIconTextChanged
windowIconTextChanged(self, str) [signal] windowTitleChanged
windowTitleChanged(self, str) [signal] -
class
Behavior
¶ Bases:
int
-
ShowDialog
= 0¶
-
SignalOnly
= 1¶
-
acceptLiveUpdates
(self) → bool¶ Returns whether the button accepts live updates from QColorDialog.
Returns: true if the button will be accepted immediately when the dialog’s color changes See also
-
actionEvent
()¶
-
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.
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.
Returns: behavior when button is clicked See also
-
changeEvent
(self, e: QEvent)¶
-
checkStateSet
()¶
-
childEvent
()¶
-
closeEvent
()¶
-
color
(self) → QColor¶ Return the currently selected color.
Returns: currently selected color See also
-
colorChanged
¶ Is emitted whenever a new color is set for the button. The color is always valid. In case the new color is the same no signal is emitted, to avoid infinite loops.
Parameters: color – New color [signal]
-
colorClicked
¶ Emitted when the button is clicked, if the button’s behavior is set to SignalOnly
Parameters: color – button color See also
See also
behavior()
[signal]
-
colorDialogTitle
(self) → str¶ Returns the title for the color chooser dialog window.
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.
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
()¶
-
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 customise their display colors based on the context.
Returns: context string for the color button’s color swatch grids See also
-
contextMenuEvent
()¶
-
copyColor
(self)¶ Copies the current color to the clipboard
See also
-
create
()¶
-
customEvent
()¶
-
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.
Returns: default color for the button. Returns an invalid QColor if the default color option is disabled.
See also
-
destroy
()¶
-
disconnectNotify
()¶
-
dragEnterEvent
(self, e: QDragEnterEvent)¶ Reimplemented to accept dragged colors
-
dragLeaveEvent
(self, e: QDragLeaveEvent)¶ Reimplemented to reset button appearance after drag leave
-
dragMoveEvent
()¶
-
dropEvent
(self, e: QDropEvent)¶ Reimplemented to accept dropped colors
-
enterEvent
()¶
-
event
(self, e: QEvent) → bool¶
-
focusInEvent
()¶
-
focusNextChild
()¶
-
focusNextPrevChild
()¶
-
focusOutEvent
()¶
-
focusPreviousChild
()¶
-
hideEvent
()¶
-
hitButton
()¶
-
initPainter
()¶
-
initStyleOption
()¶
-
inputMethodEvent
()¶
-
isNull
(self) → bool¶ Returns true if the current color is null.
New in version 2.16.
See also
See also
-
isSignalConnected
()¶
-
keyPressEvent
(self, e: QKeyEvent)¶ Reimplemented to allow canceling color pick via keypress, and sample via space bar press
-
keyReleaseEvent
()¶
-
leaveEvent
()¶
-
metric
()¶
-
minimumSizeHint
(self) → QSize¶
-
mouseDoubleClickEvent
()¶
-
mouseMoveEvent
(self, e: QMouseEvent)¶ Reimplemented to allow dragging colors from button
-
mousePressEvent
(self, e: QMouseEvent)¶ Reimplemented to detect right mouse button clicks on the color button and allow dragging colors
-
mouseReleaseEvent
(self, e: QMouseEvent)¶ Reimplemented to allow color picking
-
moveEvent
()¶
-
nativeEvent
()¶
-
nextCheckState
()¶
-
noColorString
(self) → str¶ Returns the string used for the “no color” option in the button’s drop-down menu.
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 (see setColorDialogOptions)
-
paintEvent
()¶
-
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
()¶
-
resizeEvent
(self, event: QResizeEvent)¶
-
sender
()¶
-
senderSignalIndex
()¶
-
setAcceptLiveUpdates
(self, accept: bool)¶ Sets whether the button accepts live updates from QColorDialog. Live updates may cause changes that are not undoable on QColorDialog cancel.
Parameters: accept – set to true to enable live updates See also
-
setAllowOpacity
(self, allowOpacity: bool)¶ Sets whether opacity modification (transparency) is permitted for the color. Defaults to false.
Parameters: allowOpacity – 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 – behavior when button is clicked See also
-
setButtonBackground
(self, color: Union[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 – Color for button background. If no color is specified, the button’s current color will be used
-
setColor
(self, color: Union[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 – new color for the button See also
-
setColorDialogTitle
(self, title: str)¶ Set the title for the color chooser dialog window.
Parameters: title – 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 – 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 customise their display colors based on the context.
Parameters: context – context string for the color button’s color swatch grids See also
-
setDefaultColor
(self, color: Union[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 – 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 – 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 (see setColorDialogOptions)
-
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 – 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 – 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 (see setColorDialogOptions)
-
setShowNull
(self, showNull: bool)¶ Sets whether a set to null (clear) option is shown in the button’s drop-down menu.
Parameters: showNull – set to true to show a null option New in version 2.16.
See also
See also
-
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 (see setColorDialogOptions) then the color will not be changed.
See also
-
setToNull
(self)¶ Sets color to null.
See also
See also
New in version 2.16.
-
showEvent
(self, e: QShowEvent)¶
-
showMenu
(self) → bool¶ Returns whether the drop-down menu is shown for the button.
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.
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 (see setColorDialogOptions)
-
showNull
(self) → bool¶ Returns whether the set to null (clear) option is shown in the button’s drop-down menu.
New in version 2.16.
See also
See also
-
sizeHint
(self) → QSize¶
-
tabletEvent
()¶
-
timerEvent
()¶
-
transparentBackground
() → QPixmap¶ Returns a checkboard pattern pixmap for use as a background to transparent colors
-
updateMicroFocus
()¶
-
wheelEvent
()¶
-
class