Class: QgsColorRampTransformer

class qgis.core.QgsColorRampTransformer(minValue: float = 0, maxValue: float = 1, ramp: QgsColorRamp = None, nullColor: Union[QColor, Qt.GlobalColor, QGradient] = QColor(0, 0, 0, 0))

Bases: QgsPropertyTransformer

Constructor for QgsColorRampTransformer.

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

  • maxValue (float = 1) – maximum expected value

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

  • nullColor (Union[QColor) – color to return for null values

QgsColorRampTransformer(other: QgsColorRampTransformer) Copy constructor

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

Methods

clone

rtype

QgsColorRampTransformer

color

Calculates the color corresponding to a specific value.

colorRamp

Returns the color ramp used for calculating property colors.

loadVariant

param definition

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.

toExpression

param baseExpression

toVariant

rtype

Any

transform

param context

transformNumeric

Applies base class numeric transformations.

transformerType

rtype

QgsPropertyTransformer.Type

clone(self)QgsColorRampTransformer
Return type

QgsColorRampTransformer

color(self, value: float) → QColor

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

Returns the color ramp used for calculating property colors.

Return type

QgsColorRamp

Returns

color ramp

See also

setColorRamp()

loadVariant(self, definition: Any) → bool
Parameters

definition (Any) –

Return type

bool

nullColor(self) → QColor

Returns the color corresponding to a null value.

See also

setNullColor()

Return type

QColor

rampName(self) → str

Returns the color ramp’s name.

See also

setRampName()

Return type

str

setColorRamp(self, ramp: QgsColorRamp)

Sets the color ramp to use for calculating property colors.

Parameters

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

See also

colorRamp()

setNullColor(self, color: Union[QColor, Qt.GlobalColor, QGradient])

Sets the color corresponding to a null value.

Parameters

color (Union[QColor) – null color

See also

nullColor()

setRampName(self, name: str)

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 (str) –

toExpression(self, baseExpression: str) → str
Parameters

baseExpression (str) –

Return type

str

toVariant(self) → Any
Return type

Any

transform(self, context: QgsExpressionContext, value: Any) → Any
Parameters
Return type

Any

transformNumeric(self, input: float) → float

Applies base class numeric transformations. Derived classes should call this to transform an input numeric value before they apply any transform to the result. This applies any curve transforms which may exist on the transformer.

transformerType(self)QgsPropertyTransformer.Type
Return type

QgsPropertyTransformer.Type