Subgroup: Gradient

Class: QgsGradientColorRamp

class qgis.core.QgsGradientColorRamp(color1: Union[QColor, Qt.GlobalColor, QGradient] = DEFAULT_GRADIENT_COLOR1, color2: Union[QColor, Qt.GlobalColor, QGradient] = DEFAULT_GRADIENT_COLOR2, discrete: bool = False, stops: object = QgsGradientStopsList())

Bases: qgis._core.QgsColorRamp

Constructor for QgsGradientColorRamp

Parameters:
  • color1 – start color, corresponding to a position of 0.0
  • color2 – end color, corresponding to a position of 1.0
  • discrete – set to true for discrete interpolation instead of smoothly

interpolating between colors :param stops: optional list of additional color stops

QgsGradientColorRamp(QgsGradientColorRamp)

Gradient color ramp, which smoothly interpolates between two colors and also

supports optional extra color stops.

New in version 3.0: Methods

addStopsToGradient Copy color ramp stops to a QGradient
clone
color
color1 Returns the gradient start color.
color2 Returns the gradient end color.
convertToDiscrete Converts a gradient with existing color stops to or from discrete interpolation.
count
create Creates a new QgsColorRamp from a map of properties
info Returns any additional info attached to the gradient ramp (e.
invert
isDiscrete Returns true if the gradient is using discrete interpolation, rather than smoothly interpolating between colors.
properties
setColor1 Sets the gradient start color.
setColor2 Sets the gradient end color.
setDiscrete Sets whether the gradient should use discrete interpolation, rather than smoothly interpolating between colors.
setInfo Sets additional info to attach to the gradient ramp (e.
setStops Sets the list of intermediate gradient stops for the ramp.
stops Returns the list of intermediate gradient stops for the ramp.
type
value

Signals

Attributes

addStopsToGradient(self, gradient: QGradient, opacity: float = 1)

Copy color ramp stops to a QGradient

Parameters:
  • gradient – gradient to copy stops into
  • opacity – opacity multiplier. Opacity of colors will be multiplied

by this factor before adding to the gradient.

New in version 2.1.

clone(self) → QgsGradientColorRamp
color(self, value: float) → QColor
color1(self) → QColor

Returns the gradient start color.

See also

setColor1()

See also

color2()

color2(self) → QColor

Returns the gradient end color.

See also

setColor2()

See also

color1()

convertToDiscrete(self, discrete: bool)

Converts a gradient with existing color stops to or from discrete interpolation.

Parameters:discrete – set to true to convert the gradient stops to discrete,

or false to convert them to smooth interpolation

See also

isDiscrete()

count(self) → int
create(properties: Dict[str, str] = {}) → QgsColorRamp

Creates a new QgsColorRamp from a map of properties

info(self) → Dict[str, str]

Returns any additional info attached to the gradient ramp (e.g., authorship notes)

See also

setInfo()

invert(self)
isDiscrete(self) → bool

Returns true if the gradient is using discrete interpolation, rather than smoothly interpolating between colors.

See also

setDiscrete()

properties(self) → Dict[str, str]
setColor1(self, color: Union[QColor, Qt.GlobalColor, QGradient])

Sets the gradient start color.

Parameters:color – start color

See also

color1()

See also

setColor2()

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

Sets the gradient end color.

Parameters:color – end color

See also

color2()

See also

setColor1()

setDiscrete(self, discrete: bool)

Sets whether the gradient should use discrete interpolation, rather than smoothly interpolating between colors.

Parameters:discrete – set to true to use discrete interpolation

See also

isDiscrete()

setInfo(self, info: Dict[str, str])

Sets additional info to attach to the gradient ramp (e.g., authorship notes)

Parameters:info – map of string info to attach

See also

info()

setStops(self, stops: object)

Sets the list of intermediate gradient stops for the ramp.

Parameters:stops – list of stops. Any existing color stops will be replaced. The stop

list will be automatically reordered so that stops are listed in ascending offset order.

See also

stops()

stops(self) → object

Returns the list of intermediate gradient stops for the ramp.

See also

setStops()

type(self) → str
value(self, index: int) → float