Class: QgsColorRampTransformer

QgsPropertyTransformer subclass for transforming a numeric value into a color from a color ramp.

Class Hierarchy

Inheritance diagram of qgis.core.QgsColorRampTransformer

Base classes

QgsPropertyTransformer

Abstract base class for objects which transform the calculated value of a property.

Methods

color

Calculates the color corresponding to a specific value.

colorRamp

Returns the color ramp used for calculating property colors.

nullColor

Returns the color corresponding to a null value.

rampName

Returns the color ramp's name.

setColorRamp

Sets the color ramp to use for calculating property colors.

setNullColor

Sets the color corresponding to a null value.

setRampName

Sets the color ramp's name.

class qgis.core.QgsColorRampTransformer[source]

Bases: QgsPropertyTransformer

__init__(minValue: float = 0, maxValue: float = 1, ramp: QgsColorRamp | None = None, nullColor: QColor | Qt.GlobalColor = QColor(0, 0, 0, 0), rampName: str | None = '')

Constructor for QgsColorRampTransformer.

Parameters:
  • minValue (float = 0) – minimum expected value

  • maxValue (float = 1) – maximum expected value

  • ramp (Optional[QgsColorRamp] = None) – source color ramp. Ownership is transferred to the transformer.

  • nullColor (Union[QColor, Qt.GlobalColor] = QColor(0, 0, 0, 0)) – color to return for null values

  • rampName (Optional[str] = '') – name of the source color ramp (since QGIS 3.36)

__init__(other: QgsColorRampTransformer)
Parameters:

other (QgsColorRampTransformer)

color(self, value: float) QColor[source]

Calculates the color corresponding to a specific value.

Parameters:

value (float) – value to calculate color for

Return type:

QColor

Returns:

calculated color using transformer’s parameters and type

colorRamp(self) QgsColorRamp | None[source]

Returns the color ramp used for calculating property colors.

Return type:

Optional[QgsColorRamp]

Returns:

color ramp

See also

setColorRamp()

nullColor(self) QColor[source]

Returns the color corresponding to a null value.

See also

setNullColor()

Return type:

QColor

rampName(self) str[source]

Returns the color ramp’s name.

See also

setRampName()

Return type:

str

setColorRamp(self, ramp: QgsColorRamp | None)[source]

Sets the color ramp to use for calculating property colors.

Parameters:

ramp (Optional[QgsColorRamp]) – color ramp, ownership of ramp is transferred to the transformer.

See also

colorRamp()

setNullColor(self, color: QColor | Qt.GlobalColor)[source]

Sets the color corresponding to a null value.

Parameters:

color (Union[QColor, Qt.GlobalColor]) – null color

See also

nullColor()

setRampName(self, name: str | None)[source]

Sets the color ramp’s name. The ramp name must be set to match a color ramp available in the style database for conversion to expression to work correctly.

See also

rampName()

Parameters:

name (Optional[str])