Class: QgsColorWidget¶
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).
Class Hierarchy¶
Base classes¶
Subclasses¶
A color box widget. |
|
A preview box which displays one or two colors as swatches. |
|
A color ramp widget. |
|
A composite horizontal color ramp widget and associated spinbox for manual value entry. |
|
A line edit widget which displays colors as text and accepts string representations of colors. |
|
A color wheel widget. |
Enums
Specified the color component unit |
Methods
Returns the current color for the widget |
|
Returns color widget type of color, either RGB, HSV, CMYK, or Invalid if this component value is Multiple or Alpha |
|
Returns the color component which the widget controls |
|
Returns the range of valid values for the color widget's component |
|
Returns the current value of the widget's color component |
|
Returns the current value of the widget's color component |
|
Returns the hue for the widget. |
|
Returns the hue for the widget. |
|
Generates a checkboard pattern pixmap for use as a background to transparent colors |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsColorWidget. See the FAQ for more details.
Sets the color for the widget |
|
Sets the color component which the widget controls |
|
Alters the widget's color by setting the value for the widget's color component |
|
Alters the widget's color by setting the value for the widget's color component |
Static Methods
Alters a color by modifying the value of a specific color component |
|
Alters a color by modifying the value of a specific color component |
|
Returns color component unit |
|
Create an icon for dragging colors |
Signals
Emitted when the widget's color changes |
|
Emitted when mouse hovers over widget. |
Attributes
- class qgis.gui.QgsColorWidget[source]¶
Bases:
QWidget
- __init__(parent: QWidget | None = None, component: QgsColorWidget.ColorComponent = QgsColorWidget.Multiple)
Construct a new color widget.
- Parameters:
parent (Optional[QWidget] = None) – parent QWidget for the widget
component (QgsColorWidget.ColorComponent = QgsColorWidget.Multiple) – color component the widget alters
- Alpha = 7¶
- Black = 11¶
- Blue = 3¶
- class ColorComponent¶
Bases:
int
- class ComponentUnit(*values)¶
Bases:
IntEnum
Specified the color component unit
Scaled0to255
: Values in the range 0-255Percent
: Percent values in the range 0-100Degree
: Degree values in the range 0-359
- Degree = 2¶
- Percent = 1¶
- Scaled0to255 = 0¶
- Cyan = 8¶
- Green = 2¶
- Hue = 4¶
- Magenta = 9¶
- Multiple = 0¶
- Red = 1¶
- Saturation = 5¶
- Value = 6¶
- Yellow = 10¶
- static alterColor(color: QColor | Qt.GlobalColor, component: QgsColorWidget.ColorComponent, newValue: int)[source]¶
Alters a color by modifying the value of a specific color component
- Parameters:
color (Union[QColor, Qt.GlobalColor]) – color to alter
component (QgsColorWidget.ColorComponent) – color component to alter
newValue (int) – new value of color component in the range between 0 and the value returned by
componentRange()
. Values are automatically clipped to a valid range for the color component.
Deprecated since version 3.40: Use
alterColorF()
instead.
- static alterColorF(color: QColor | Qt.GlobalColor, component: QgsColorWidget.ColorComponent, newValue: float)[source]¶
Alters a color by modifying the value of a specific color component
- Parameters:
color (Union[QColor, Qt.GlobalColor]) – color to alter
component (QgsColorWidget.ColorComponent) – color component to alter
newValue (float) – new value of color component in the range between 0 and the value returned by
componentRange()
. Values are automatically clipped to range 0.0-1.0
Added in version 3.40.
- color(self) QColor [source]¶
Returns the current color for the widget
- Return type:
QColor
- Returns:
current widget color
See also
- signal colorChanged(color: QColor)[source]¶
Emitted when the widget’s color changes
- Parameters:
color (QColor) – new widget color
- colorSpec(self) QColor.Spec [source]¶
Returns color widget type of color, either RGB, HSV, CMYK, or Invalid if this component value is Multiple or Alpha
- Return type:
QColor.Spec
- colorSpec(component: QgsColorWidget.ColorComponent) QColor.Spec [source]
Returns
component
type of color, either RGB, HSV, CMYK, or Invalid ifcomponent
value is Multiple or Alpha- Parameters:
component (QgsColorWidget.ColorComponent)
- Return type:
QColor.Spec
- component(self) QgsColorWidget.ColorComponent [source]¶
Returns the color component which the widget controls
- Return type:
- Returns:
color component for widget
See also
- componentRange(self) int [source]¶
Returns the range of valid values for the color widget’s component
- Return type:
int
- Returns:
maximum value allowed for color component, or -1 if widget has multiple components
- componentRange(component: QgsColorWidget.ColorComponent) int [source]
Returns the range of valid values a color component
- Return type:
int
- Returns:
maximum value allowed for color component
- Parameters:
component (QgsColorWidget.ColorComponent)
- static componentUnit(component: QgsColorWidget.ColorComponent) QgsColorWidget.ComponentUnit [source]¶
Returns color
component
unit- Parameters:
component (QgsColorWidget.ColorComponent)
- Return type:
- componentValue(self) int [source]¶
Returns the current value of the widget’s color component
- Return type:
int
- Returns:
value of color component, or -1 if widget has multiple components or an invalid color set
See also
See also
Deprecated since version 3.40: Use
componentValueF()
instead.
- componentValue(self, component: QgsColorWidget.ColorComponent) int [source]
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 (QgsColorWidget.ColorComponent) – color component to return
- Return type:
int
- Returns:
value of color component in the range between 0 and the value returned by
componentRange()
, or -1 if widget has an invalid color set
See also
Deprecated since version 3.40: Use
componentValueF()
instead.
- componentValueF(self) float [source]¶
Returns the current value of the widget’s color component
- Return type:
float
- Returns:
value of color component, or -1 if widget has multiple components or an invalid color set
See also
See also
Added in version 3.40.
- componentValueF(self, component: QgsColorWidget.ColorComponent) float [source]
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 (QgsColorWidget.ColorComponent) – color component to return
- Return type:
float
- Returns:
value of color component in the range 0-1.0, or -1 if widget has an invalid color set
See also
Added in version 3.40.
- static createDragIcon(color: QColor | Qt.GlobalColor) QPixmap [source]¶
Create an icon for dragging colors
- Parameters:
color (Union[QColor, Qt.GlobalColor]) – for icon
- Return type:
QPixmap
- hue(self) int [source]¶
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 in the range 0-359
Deprecated since version 3.40: Use
hueF()
instead.
- hueF(self) float [source]¶
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:
float
- Returns:
explicitly set hue for widget in the range 0-1.0
Added in version 3.40.
- virtual setColor(self, color: QColor | Qt.GlobalColor, emitSignals: bool = False)[source]¶
Sets the color for the widget
- Parameters:
color (Union[QColor, Qt.GlobalColor]) – widget color
emitSignals (bool = False) – set to
True
to emit the colorChanged signal after setting color
See also
- virtual setComponent(self, component: QgsColorWidget.ColorComponent)[source]¶
Sets the color component which the widget controls
- Parameters:
component (QgsColorWidget.ColorComponent) – color component for widget
See also
- virtual setComponentValue(self, value: int)[source]¶
Alters the widget’s color by setting the value for the widget’s color component
- Parameters:
value (int) – value for widget’s color component in the range between 0 and the value returned by
componentRange()
. This value is automatically clipped to the range of valid values for the color component.
See also
See also
Note
this method has no effect if the widget is set to the QgsColorWidget.Multiple component
Deprecated since version 3.40: Use
setComponentValueF()
instead.
- virtual setComponentValueF(self, value: float)[source]¶
Alters the widget’s color by setting the value for the widget’s color component
- Parameters:
value (float) – value for widget’s color component in the range 0.0-1.0. This value is automatically clipped to the range 0.0-1.0.
See also
See also
Note
this method has no effect if the widget is set to the QgsColorWidget.Multiple component
Added in version 3.40.
- transparentBackground() QPixmap ¶
Generates a checkboard pattern pixmap for use as a background to transparent colors
- Return type:
QPixmap
- Returns:
checkerboard pixmap