Class: QgsColorWidget

class qgis.gui.QgsColorWidget(parent: QWidget = None, component: QgsColorWidget.ColorComponent = QgsColorWidget.Multiple)

Bases: PyQt5.QtWidgets.QWidget

Construct a new color widget.

Parameters:
  • parent – parent QWidget for the widget
  • component – color component the widget alters

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).

New in version 2.5: Methods

actionEvent
alterColor Alters a color by modifiying the value of a specific color component
changeEvent
childEvent
closeEvent
color Returns the current color for the widget
component Returns the color component which the widget controls
componentRange Returns the range of valid values for the color widget’s component
componentValue Returns the current value of the widget’s color component
connectNotify
contextMenuEvent
create
createDragIcon Create an icon for dragging colors
customEvent
destroy
disconnectNotify
dragEnterEvent
dragLeaveEvent
dragMoveEvent
dropEvent
enterEvent
event
focusInEvent
focusNextChild
focusNextPrevChild
focusOutEvent
focusPreviousChild
hideEvent
hue Returns the hue for the widget.
initPainter
inputMethodEvent
isSignalConnected
keyPressEvent
keyReleaseEvent
leaveEvent
metric
mouseDoubleClickEvent
mouseMoveEvent
mousePressEvent
mouseReleaseEvent
moveEvent
nativeEvent
paintEvent
receivers
resizeEvent
sender
senderSignalIndex
setColor Sets the color for the widget
setComponent Sets the color component which the widget controls
setComponentValue Alters the widget’s color by setting the value for the widget’s color component
sharedPainter
showEvent
tabletEvent
timerEvent
transparentBackground Generates a checkboard pattern pixmap for use as a background to transparent colors
updateMicroFocus
wheelEvent

Signals

colorChanged Emitted when the widget’s color changes
hovered Emitted when mouse hovers over widget.

Attributes

Alpha
Blue
Green
Hue
Multiple
Red
Saturation
Value
Alpha = 7
Blue = 3
class ColorComponent

Bases: int

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

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

Parameters:
  • color – color to alter
  • component – color component to alter
  • newValue – new value of color component. Values are automatically clipped to a valid range for the color component.
changeEvent()
childEvent()
closeEvent()
color(self) → QColor

Returns the current color for the widget

Returns:current widget color

See also

setColor()

colorChanged

Emitted when the widget’s color changes

Parameters:color – new widget color [signal]
component(self) → QgsColorWidget.ColorComponent

Returns the color component which the widget controls

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

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
Returns:value of color component, or -1 if widget has an invalid color set

See also

hue()

connectNotify()
contextMenuEvent()
create()
createDragIcon(color: Union[QColor, Qt.GlobalColor, QGradient]) → QPixmap

Create an icon for dragging colors

Parameters:color – for icon
customEvent()
destroy()
disconnectNotify()
dragEnterEvent(self, e: QDragEnterEvent)
dragLeaveEvent()
dragMoveEvent()
dropEvent(self, e: QDropEvent)
enterEvent()
event()
focusInEvent()
focusNextChild()
focusNextPrevChild()
focusOutEvent()
focusPreviousChild()
hideEvent()
hovered

Emitted when mouse hovers over widget.

New in version 2.14: [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).

Returns:explicitly set hue for widget
initPainter()
inputMethodEvent()
isSignalConnected()
keyPressEvent()
keyReleaseEvent()
leaveEvent()
metric()
mouseDoubleClickEvent()
mouseMoveEvent(self, e: QMouseEvent)
mousePressEvent(self, e: QMouseEvent)
mouseReleaseEvent(self, e: QMouseEvent)
moveEvent()
nativeEvent()
paintEvent()
receivers()
resizeEvent()
sender()
senderSignalIndex()
setColor(self, color: Union[QColor, Qt.GlobalColor, QGradient], emitSignals: bool = False)

Sets the color for the widget

Parameters:
  • color – widget color
  • emitSignals – 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 – 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 – 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()
showEvent()
tabletEvent()
timerEvent()
transparentBackground() → QPixmap

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

Returns:checkerboard pixmap
updateMicroFocus()
wheelEvent()