Class: QgsColorWidget

class qgis.gui.QgsColorWidget

Bases: PyQt5.QtWidgets.QWidget

A base class for interactive color widgets. Widgets can either allow setting a single component of a color (e.g., the red or green components), or an entire color. The QgsColorWidget also keeps track of any explicitly set hue for the color, so that this information is not lost when the widget is set to a color with an ambiguous hue (e.g., black or white shades).

QgsColorWidget(parent: QWidget = None, component: QgsColorWidget.ColorComponent = QgsColorWidget.Multiple) Construct a new color widget.

Parameters:
Alpha = 7
Blue = 3
class ColorComponent

Bases: int

Green = 2
Hue = 4
Multiple = 0
Red = 1
Saturation = 5
Value = 6
actionEvent(self, QActionEvent)
alterColor(self, color: QColor | Qt.GlobalColor | QGradient, component: QgsColorWidget.ColorComponent, newValue: int)

Alters a color by modifying the value of a specific color component

Parameters:
  • color (Union[QColor) – color to alter

  • component (QgsColorWidget.ColorComponent) – color component to alter

  • newValue (int) – new value of color component. Values are automatically clipped to a valid range for the color component.

changeEvent(self, QEvent)
childEvent(self, QChildEvent)
closeEvent(self, QCloseEvent)
color(self) QColor

Returns the current color for the widget

Return type:

QColor

Returns:

current widget color

See also

setColor()

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

component(self) QgsColorWidget.ColorComponent

Returns the color component which the widget controls

Return type:

QgsColorWidget.ColorComponent

Returns:

color component for widget

See also

setComponent()

componentRange(self) int

Returns the range of valid values for the color widget’s component

Returns:

maximum value allowed for color component, or -1 if widget has multiple components

componentRange(self, component: QgsColorWidget.ColorComponent) -> int Returns the range of valid values a color component

Return type:

int

Returns:

maximum value allowed for color component

componentValue(self) int

Returns the current value of the widget’s color component

Returns:

value of color component, or -1 if widget has multiple components or an invalid color set

See also

component()

componentValue(self, component: QgsColorWidget.ColorComponent) -> int Returns the value of a component of the widget’s current color. This method correctly handles hue values when the color has an ambiguous hue (e.g., black or white shades)

Parameters:

component – color component to return

Return type:

int

Returns:

value of color component, or -1 if widget has an invalid color set

See also

hue()

connectNotify(self, QMetaMethod)
contextMenuEvent(self, QContextMenuEvent)
create(self, window: PyQt5.sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)
createDragIcon(color: QColor | Qt.GlobalColor | QGradient) QPixmap

Create an icon for dragging colors

Parameters:

color (Union[QColor) – for icon

Return type:

QPixmap

customEvent(self, QEvent)
destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)
disconnectNotify(self, QMetaMethod)
dragEnterEvent(self, e: QDragEnterEvent)
Parameters:

e (QDragEnterEvent) –

dragLeaveEvent(self, QDragLeaveEvent)
dragMoveEvent(self, QDragMoveEvent)
dropEvent(self, e: QDropEvent)
Parameters:

e (QDropEvent) –

enterEvent(self, QEvent)
event(self, QEvent) bool
focusInEvent(self, QFocusEvent)
focusNextChild(self) bool
focusNextPrevChild(self, bool) bool
focusOutEvent(self, QFocusEvent)
focusPreviousChild(self) bool
hideEvent(self, QHideEvent)
hovered

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

hue(self) int

Returns the hue for the widget. This may differ from the hue for the QColor returned by color(), as QColor returns a hue of -1 if the color’s hue is ambiguous (e.g., if the saturation is zero).

Return type:

int

Returns:

explicitly set hue for widget

initPainter(self, QPainter)
inputMethodEvent(self, QInputMethodEvent)
isSignalConnected(self, QMetaMethod) bool
keyPressEvent(self, QKeyEvent)
keyReleaseEvent(self, QKeyEvent)
leaveEvent(self, QEvent)
metric(self, QPaintDevice.PaintDeviceMetric) int
mouseDoubleClickEvent(self, QMouseEvent)
mouseMoveEvent(self, e: QMouseEvent)
Parameters:

e (QMouseEvent) –

mousePressEvent(self, e: QMouseEvent)
Parameters:

e (QMouseEvent) –

mouseReleaseEvent(self, e: QMouseEvent)
Parameters:

e (QMouseEvent) –

moveEvent(self, QMoveEvent)
nativeEvent(self, Union[QByteArray, bytes, bytearray], PyQt5.sip.voidptr) Tuple[bool, int]
paintEvent(self, QPaintEvent)
receivers(self, PYQT_SIGNAL) int
resizeEvent(self, QResizeEvent)
sender(self) QObject
senderSignalIndex(self) int
setColor(self, color: QColor | Qt.GlobalColor | QGradient, emitSignals: bool = False)

Sets the color for the widget

Parameters:
  • color (Union[QColor) – widget color

  • emitSignals (bool = False) – set to True to emit the colorChanged signal after setting color

See also

color()

setComponent(self, component: QgsColorWidget.ColorComponent)

Sets the color component which the widget controls

Parameters:

component (QgsColorWidget.ColorComponent) – color component for widget

See also

component()

setComponentValue(self, value: int)

Alters the widget’s color by setting the value for the widget’s color component

Parameters:

value (int) – value for widget’s color component. This value is automatically clipped to the range of valid values for the color component.

See also

componentValue()

See also

setComponent()

Note

this method has no effect if the widget is set to the QgsColorWidget.Multiple component

sharedPainter(self) QPainter
showEvent(self, QShowEvent)
tabletEvent(self, QTabletEvent)
timerEvent(self, QTimerEvent)
transparentBackground() QPixmap

Generates a checkboard pattern pixmap for use as a background to transparent colors

Return type:

QPixmap

Returns:

checkerboard pixmap

updateMicroFocus(self)
wheelEvent(self, QWheelEvent)