Class: QgsGradientColorRamp¶
- class qgis.core.QgsGradientColorRamp¶
Bases:
QgsColorRamp
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra color stops.
New in version 3.0.
QgsGradientColorRamp(color1: Union[QColor, Qt.GlobalColor, QGradient] = DEFAULT_GRADIENT_COLOR1, color2: Union[QColor, Qt.GlobalColor, QGradient] = DEFAULT_GRADIENT_COLOR2, discrete: bool = False, stops: Iterable[QgsGradientStop] = []) 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 colorsstops – optional list of additional color stops
QgsGradientColorRamp(
QgsGradientColorRamp
)Methods
Copy color ramp stops to a QGradient
- rtype:
QgsGradientColorRamp
- param value:
Returns the gradient start color.
Returns the gradient end color.
Returns the color specification in which the color component interpolation will occur.
Converts a gradient with existing color stops to or from discrete interpolation.
- rtype:
int
Creates a new
QgsColorRamp
from a map of propertiesReturns the direction to traverse the color wheel using when interpolating hue-based color specifications.
Returns any additional info attached to the gradient ramp (e.g., authorship notes)
Returns
True
if the gradient is using discrete interpolation, rather than smoothly interpolating between colors.- rtype:
Dict[str, Any]
Sets the gradient start color.
Sets the gradient end color.
Sets the color specification in which the color component interpolation will occur.
Sets the
direction
to traverse the color wheel using when interpolating hue-based color specifications.Sets whether the gradient should use discrete interpolation, rather than smoothly interpolating between colors.
Sets additional info to attach to the gradient ramp (e.g., authorship notes)
Sets the list of intermediate gradient stops for the ramp.
Returns the list of intermediate gradient stops for the ramp.
- rtype:
str
Returns the string identifier for QgsGradientColorRamp.
- param index:
- addStopsToGradient(self, gradient: QGradient, opacity: float = 1)¶
Copy color ramp stops to a QGradient
- Parameters:
gradient (QGradient) – gradient to copy stops into
opacity (float = 1) – opacity multiplier. Opacity of colors will be multiplied by this factor before adding to the gradient.
New in version 2.1.
- clone(self) QgsGradientColorRamp ¶
- Return type:
- color(self, value: float) QColor ¶
- Parameters:
value (float) –
- Return type:
QColor
- color1(self) QColor ¶
Returns the gradient start color.
See also
See also
- Return type:
QColor
- color2(self) QColor ¶
Returns the gradient end color.
See also
See also
- Return type:
QColor
- colorSpec(self) QColor.Spec ¶
Returns the color specification in which the color component interpolation will occur.
For multi-stop gradients this color spec will be used for the portion of the color ramp leading into the final stop (i.e.
color2()
).See also
New in version 3.24.
- Return type:
QColor.Spec
- convertToDiscrete(self, discrete: bool)¶
Converts a gradient with existing color stops to or from discrete interpolation.
- Parameters:
discrete (bool) – set to
True
to convert the gradient stops to discrete, orFalse
to convert them to smooth interpolation
See also
- count(self) int ¶
- Return type:
int
- create(properties: Dict[str, Any] = {}) QgsColorRamp ¶
Creates a new
QgsColorRamp
from a map of properties- Parameters:
properties (Dict[str) –
- Return type:
- direction(self) Qgis.AngularDirection ¶
Returns the direction to traverse the color wheel using when interpolating hue-based color specifications.
For multi-stop gradients this direction will be used for the portion of the color ramp leading into the final stop (i.e.
color2()
).See also
New in version 3.24.
- Return type:
- info(self) Dict[str, str] ¶
Returns any additional info attached to the gradient ramp (e.g., authorship notes)
See also
- Return type:
Dict[str, str]
- invert(self)¶
- isDiscrete(self) bool ¶
Returns
True
if the gradient is using discrete interpolation, rather than smoothly interpolating between colors.See also
- Return type:
bool
- properties(self) Dict[str, Any] ¶
- Return type:
Dict[str, Any]
- setColor1(self, color: QColor | Qt.GlobalColor | QGradient)¶
Sets the gradient start color.
- Parameters:
color (Union[QColor) – start color
See also
See also
- setColor2(self, color: QColor | Qt.GlobalColor | QGradient)¶
Sets the gradient end color.
- Parameters:
color (Union[QColor) – end color
See also
See also
- setColorSpec(self, spec: QColor.Spec)¶
Sets the color specification in which the color component interpolation will occur.
Only QColor.Spec.Rgb, QColor.Spec.Hsv and QColor.Spec.Hsl are currently supported.
For multi-stop gradients this color spec will be used for the portion of the color ramp leading into the final stop (i.e.
color2()
).See also
New in version 3.24.
- Parameters:
spec (QColor.Spec) –
- setDirection(self, direction: Qgis.AngularDirection)¶
Sets the
direction
to traverse the color wheel using when interpolating hue-based color specifications.For multi-stop gradients this direction will be used for the portion of the color ramp leading into the final stop (i.e.
color2()
).See also
New in version 3.24.
- Parameters:
direction (Qgis.AngularDirection) –
- setDiscrete(self, discrete: bool)¶
Sets whether the gradient should use discrete interpolation, rather than smoothly interpolating between colors.
- Parameters:
discrete (bool) – set to
True
to use discrete interpolation
See also
See also
- setInfo(self, info: Dict[str, str])¶
Sets additional info to attach to the gradient ramp (e.g., authorship notes)
- Parameters:
info (Dict[str) – map of string info to attach
See also
- setStops(self, stops: Iterable[QgsGradientStop])¶
Sets the list of intermediate gradient stops for the ramp.
- Parameters:
stops (Iterable[QgsGradientStop]) – 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(self) List[QgsGradientStop] ¶
Returns the list of intermediate gradient stops for the ramp.
See also
- Return type:
List[QgsGradientStop]
- type(self) str ¶
- Return type:
str
- typeString() str ¶
Returns the string identifier for QgsGradientColorRamp.
New in version 3.16.
- Return type:
str
- value(self, index: int) float ¶
- Parameters:
index (int) –
- Return type:
float