Class: QgsColorRampWidget

A color ramp widget. This widget consists of an interactive box filled with a color which varies along its length by a single color component (e.g., varying saturation from 0 to 100%).

Class Hierarchy

Inheritance diagram of qgis.gui.QgsColorRampWidget

Base classes

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

QWidget

QObject

QPaintDevice

Methods

interiorMargin

Fetches the margin between the edge of the widget and the ramp

orientation

Fetches the orientation for the color ramp

setInteriorMargin

Sets the margin between the edge of the widget and the ramp

setMarkerSize

Sets the size for drawing the triangular markers on the ramp

setOrientation

Sets the orientation for the color ramp

setShowFrame

Sets whether the ramp should be drawn within a frame

showFrame

Fetches whether the ramp is drawn within a frame

Signals

valueChanged

Emitted when the widget's color component value changes

valueChangedF

Emitted when the widget's color component value changes

Attributes

Horizontal

Vertical

class qgis.gui.QgsColorRampWidget[source]

Bases: QgsColorWidget

__init__(parent: QWidget | None = None, component: QgsColorWidget.ColorComponent = QgsColorWidget.Red, orientation: QgsColorRampWidget.Orientation = QgsColorRampWidget.Horizontal)

Construct a new color ramp widget.

Parameters:
  • parent (Optional[QWidget] = None) – parent QWidget for the widget

  • component (QgsColorWidget.ColorComponent = QgsColorWidget.Red) – color component which varies along the ramp

  • orientation (QgsColorRampWidget.Orientation = QgsColorRampWidget.Horizontal) – orientation for widget

Horizontal = 0
class Orientation

Bases: int

Vertical = 1
interiorMargin(self) int[source]

Fetches the margin between the edge of the widget and the ramp

Return type:

int

Returns:

margin around the ramp

orientation(self) QgsColorRampWidget.Orientation[source]

Fetches the orientation for the color ramp

Return type:

QgsColorRampWidget.Orientation

Returns:

orientation for the ramp

See also

setOrientation()

setInteriorMargin(self, margin: int)[source]

Sets the margin between the edge of the widget and the ramp

Parameters:

margin (int) – margin around the ramp

See also

interiorMargin()

setMarkerSize(self, markerSize: int)[source]

Sets the size for drawing the triangular markers on the ramp

Parameters:

markerSize (int) – marker size in pixels

setOrientation(self, orientation: QgsColorRampWidget.Orientation)[source]

Sets the orientation for the color ramp

Parameters:

orientation (QgsColorRampWidget.Orientation) – new orientation for the ramp

See also

orientation()

setShowFrame(self, showFrame: bool)[source]

Sets whether the ramp should be drawn within a frame

Parameters:

showFrame (bool) – set to True to draw a frame around the ramp

See also

showFrame()

showFrame(self) bool[source]

Fetches whether the ramp is drawn within a frame

Return type:

bool

Returns:

True if a frame is drawn around the ramp

See also

setShowFrame()

signal valueChanged[source]

Emitted when the widget’s color component value changes

Parameters:

value – new value of color component in the range between 0 and the value returned by componentRange()

Deprecated since version 3.40: Use valueChangedF() instead.

signal valueChangedF(value: float)[source]

Emitted when the widget’s color component value changes

Parameters:

value (float) – new value of color component in the range 0.0-1.0

Added in version 3.40.