Class: QgsGradientFillSymbolLayer

A fill symbol layer which draws a smooth color gradient over a polygon.

Class Hierarchy

Inheritance diagram of qgis.core.QgsGradientFillSymbolLayer

Base classes

QgsFillSymbolLayer

Abstract base class for fill symbol layers.

QgsSymbolLayer

Abstract base class for symbol layers.

Enums

GradientColorType

alias of GradientColorSource

GradientCoordinateMode

alias of SymbolCoordinateReference

GradientSpread

Gradient spread options, which control how gradients are rendered outside of their start and end points.

GradientType

Gradient types.

Methods

color2

Returns the color for endpoint of gradient, only used if the gradient color type is set to SimpleTwoColor.

colorRamp

Returns the color ramp used for the gradient fill.

coordinateMode

Returns the coordinate mode for gradient, which controls how the gradient stops are positioned.

gradientColorType

Returns the gradient color mode, which controls how gradient color stops are created.

gradientSpread

Returns the gradient spread mode, which controls how the gradient behaves outside of the predefined stops.

gradientType

Returns the type of gradient, e.g., linear or radial.

offset

Returns the offset by which polygons will be translated during rendering.

offsetMapUnitScale

Returns the map unit scale for the fill's offset.

offsetUnit

Returns the units for the fill's offset.

referencePoint1

Returns the starting point of gradient fill, in the range [0,0] - [1,1].

referencePoint1IsCentroid

Returns whether the starting point for the gradient is taken from the feature centroid.

referencePoint2

Returns the end point of gradient fill, in the range [0,0] - [1,1].

referencePoint2IsCentroid

Returns whether the end point for the gradient is taken from the feature centroid.

setColor2

Sets the color for endpoint of gradient, only used if the gradient color type is set to SimpleTwoColor.

setColorRamp

Sets the color ramp used for the gradient fill.

setCoordinateMode

Sets the coordinate mode for gradient, which controls how the gradient stops are positioned.

setGradientColorType

Sets the gradient color mode, which controls how gradient color stops are created.

setGradientSpread

Sets the gradient spread mode, which controls how the gradient behaves outside of the predefined stops.

setGradientType

Sets the type of gradient, e.g., linear or radial.

setOffset

Sets an offset by which polygons will be translated during rendering.

setOffsetMapUnitScale

Sets the map unit scale for the fill's offset.

setOffsetUnit

Sets the unit for the fill's offset.

setReferencePoint1

Sets the starting point of gradient fill, in the range [0,0] - [1,1].

setReferencePoint1IsCentroid

Sets whether the starting point for the gradient is taken from the feature centroid.

setReferencePoint2

Sets the end point of gradient fill, in the range [0,0] - [1,1].

setReferencePoint2IsCentroid

Sets whether the end point for the gradient is taken from the feature centroid.

Static Methods

create

Creates a new QgsGradientFillSymbolLayer using the specified properties map containing symbol properties (see properties()).

class qgis.core.QgsGradientFillSymbolLayer[source]

Bases: QgsFillSymbolLayer

__init__(color: QColor | Qt.GlobalColor = DEFAULT_SIMPLEFILL_COLOR, color2: QColor | Qt.GlobalColor = Qt.white, gradientColorType: Qgis.GradientColorSource = Qgis.GradientColorSource.SimpleTwoColor, gradientType: Qgis.GradientType = Qgis.GradientType.Linear, coordinateMode: Qgis.SymbolCoordinateReference = Qgis.SymbolCoordinateReference.Feature, gradientSpread: Qgis.GradientSpread = Qgis.GradientSpread.Pad)

Constructor for QgsGradientFillSymbolLayer.

Parameters:
  • color (Union[QColor, Qt.GlobalColor] = DEFAULT_SIMPLEFILL_COLOR)

  • color2 (Union[QColor, Qt.GlobalColor] = Qt.white)

  • gradientColorType (Qgis.GradientColorSource = Qgis.GradientColorSource.SimpleTwoColor)

  • gradientType (Qgis.GradientType = Qgis.GradientType.Linear)

  • coordinateMode (Qgis.SymbolCoordinateReference = Qgis.SymbolCoordinateReference.Feature)

  • gradientSpread (Qgis.GradientSpread = Qgis.GradientSpread.Pad)

GradientColorType

alias of GradientColorSource

GradientCoordinateMode

alias of SymbolCoordinateReference

class GradientSpread(*values)

Bases: IntEnum

Gradient spread options, which control how gradients are rendered outside of their start and end points.

Note

Prior to QGIS 3.24 this was available as QgsGradientFillSymbolLayer.GradientSpread

Added in version 3.24.

  • Pad: Pad out gradient using colors at endpoint of gradient

  • Reflect: Reflect gradient

  • Repeat: Repeat gradient

class GradientType(*values)

Bases: IntEnum

Gradient types.

Note

Prior to QGIS 3.24 this was available as QgsGradientFillSymbolLayer.GradientType

Added in version 3.24.

  • Linear: Linear gradient

  • Radial: Radial (circular) gradient

  • Conical: Conical (polar) gradient

color2(self) QColor[source]

Returns the color for endpoint of gradient, only used if the gradient color type is set to SimpleTwoColor.

See also

setColor2()

Return type:

QColor

colorRamp(self) QgsColorRamp | None[source]

Returns the color ramp used for the gradient fill. This is only used if the gradient color type is set to ColorRamp.

See also

setColorRamp()

Return type:

Optional[QgsColorRamp]

coordinateMode(self) Qgis.SymbolCoordinateReference[source]

Returns the coordinate mode for gradient, which controls how the gradient stops are positioned.

Return type:

Qgis.SymbolCoordinateReference

static create(properties: Dict[str, Any] = {}) QgsSymbolLayer | None[source]

Creates a new QgsGradientFillSymbolLayer using the specified properties map containing symbol properties (see properties()).

Caller takes ownership of the returned symbol layer.

Parameters:

properties (Dict[str, Any] = {})

Return type:

Optional[QgsSymbolLayer]

gradientColorType(self) Qgis.GradientColorSource[source]

Returns the gradient color mode, which controls how gradient color stops are created.

Return type:

Qgis.GradientColorSource

gradientSpread(self) Qgis.GradientSpread[source]

Returns the gradient spread mode, which controls how the gradient behaves outside of the predefined stops.

Return type:

Qgis.GradientSpread

gradientType(self) Qgis.GradientType[source]

Returns the type of gradient, e.g., linear or radial.

Return type:

Qgis.GradientType

offset(self) QPointF[source]

Returns the offset by which polygons will be translated during rendering.

Units are specified by offsetUnit().

See also

setOffset()

See also

offsetUnit()

Return type:

QPointF

offsetMapUnitScale(self) QgsMapUnitScale

Returns the map unit scale for the fill’s offset.

See also

offset()

Return type:

QgsMapUnitScale

offsetUnit(self) Qgis.RenderUnit[source]

Returns the units for the fill’s offset.

See also

setOffsetUnit()

See also

offset()

Return type:

Qgis.RenderUnit

referencePoint1(self) QPointF[source]

Returns the starting point of gradient fill, in the range [0,0] - [1,1].

Return type:

QPointF

referencePoint1IsCentroid(self) bool[source]

Returns whether the starting point for the gradient is taken from the feature centroid.

Return type:

bool

referencePoint2(self) QPointF[source]

Returns the end point of gradient fill, in the range [0,0] - [1,1].

Return type:

QPointF

referencePoint2IsCentroid(self) bool[source]

Returns whether the end point for the gradient is taken from the feature centroid.

Return type:

bool

setColor2(self, color2: QColor | Qt.GlobalColor)[source]

Sets the color for endpoint of gradient, only used if the gradient color type is set to SimpleTwoColor.

See also

color2()

Parameters:

color2 (Union[QColor, Qt.GlobalColor])

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

Sets the color ramp used for the gradient fill. This is only used if the gradient color type is set to ColorRamp.

Parameters:

ramp (Optional[QgsColorRamp]) – color ramp. Ownership is transferred.

See also

colorRamp()

setCoordinateMode(self, coordinateMode: Qgis.SymbolCoordinateReference)[source]

Sets the coordinate mode for gradient, which controls how the gradient stops are positioned.

See also

coordinateMode()

Parameters:

coordinateMode (Qgis.SymbolCoordinateReference)

setGradientColorType(self, gradientColorType: Qgis.GradientColorSource)[source]

Sets the gradient color mode, which controls how gradient color stops are created.

Parameters:

gradientColorType (Qgis.GradientColorSource)

setGradientSpread(self, gradientSpread: Qgis.GradientSpread)[source]

Sets the gradient spread mode, which controls how the gradient behaves outside of the predefined stops.

See also

gradientSpread()

Parameters:

gradientSpread (Qgis.GradientSpread)

setGradientType(self, gradientType: Qgis.GradientType)[source]

Sets the type of gradient, e.g., linear or radial.

See also

gradientType()

Parameters:

gradientType (Qgis.GradientType)

setOffset(self, offset: QPointF | QPoint)[source]

Sets an offset by which polygons will be translated during rendering.

Units are specified by offsetUnit().

See also

offset()

See also

setOffsetUnit()

Parameters:

offset (Union[QPointF, QPoint])

setOffsetMapUnitScale(self, scale: QgsMapUnitScale)[source]

Sets the map unit scale for the fill’s offset.

See also

setOffset()

Parameters:

scale (QgsMapUnitScale)

setOffsetUnit(self, unit: Qgis.RenderUnit)[source]

Sets the unit for the fill’s offset.

See also

offset()

See also

offsetUnit()

Parameters:

unit (Qgis.RenderUnit)

setReferencePoint1(self, referencePoint: QPointF | QPoint)[source]

Sets the starting point of gradient fill, in the range [0,0] - [1,1].

Parameters:

referencePoint (Union[QPointF, QPoint])

setReferencePoint1IsCentroid(self, isCentroid: bool)[source]

Sets whether the starting point for the gradient is taken from the feature centroid.

Parameters:

isCentroid (bool)

setReferencePoint2(self, referencePoint: QPointF | QPoint)[source]

Sets the end point of gradient fill, in the range [0,0] - [1,1].

Parameters:

referencePoint (Union[QPointF, QPoint])

setReferencePoint2IsCentroid(self, isCentroid: bool)[source]

Sets whether the end point for the gradient is taken from the feature centroid.

Parameters:

isCentroid (bool)