Class: QgsColorEffect

class qgis.core.QgsColorEffect

Bases: QgsPaintEffect

A paint effect which alters the colors (e.g., brightness, contrast) in a source picture.

Methods

blendMode

Returns the blend mode for the effect

boundingRect

Returns the bounding rect required for drawing the effect.

brightness

Returns the brightness modification for the effect.

clone

rtype

QgsColorEffect

colorizeColor

Returns the color used for colorizing a picture.

colorizeOn

Returns whether the effect will colorize a picture.

colorizeStrength

Returns the strength used for colorizing a picture.

contrast

Returns the contrast modification for the effect.

create

Creates a new QgsColorEffect effect from a properties string map.

draw

param context

drawSource

Draws the source QPicture onto the specified painter.

fixQPictureDpi

Applies a workaround to a QPainter to avoid an issue with incorrect scaling when drawing QPictures.

grayscaleMode

Returns whether the effect will convert a picture to grayscale.

imageOffset

Returns the offset which should be used when drawing the source image on to a destination render context.

opacity

Returns the opacity for the effect.

properties

rtype

Dict[str, str]

readProperties

param props

saturation

Returns the saturation modification for the effect.

setBlendMode

Sets the blend mode for the effect

setBrightness

Sets the brightness modification for the effect.

setColorizeColor

Sets the color used for colorizing a picture.

setColorizeOn

Sets whether the effect should colorize a picture.

setColorizeStrength

Sets the strength for colorizing a picture.

setContrast

Sets the contrast modification for the effect.

setGrayscaleMode

Sets whether the effect should convert a picture to grayscale.

setOpacity

Sets the opacity for the effect.

setSaturation

Sets the saturation modification for the effect.

source

Returns the source QPicture.

sourceAsImage

Returns the source QPicture rendered to a new QImage.

type

rtype

str

blendMode(self) → QPainter.CompositionMode

Returns the blend mode for the effect

Return type

QPainter.CompositionMode

Returns

blend mode used for drawing the effect on to a destination paint device

See also

setBlendMode()

boundingRect(self, rect: QRectF, context: QgsRenderContext) → QRectF

Returns the bounding rect required for drawing the effect. This method can be used to expand the bounding rect of a source picture to account for offset or blurring effects.

Parameters
  • rect – original source bounding rect

  • context – destination render context

Returns

modified bounding rect

See also

sourceAsImage()

brightness(self) → int

Returns the brightness modification for the effect.

Return type

int

Returns

brightness value. Values are between -255 and 255, where 0 represents no change, negative values indicate darkening and positive values indicate lightening

See also

setBrightness()

clone(self)QgsColorEffect
Return type

QgsColorEffect

colorizeColor(self) → QColor

Returns the color used for colorizing a picture. This is only used if colorizeOn() is set to True.

Return type

QColor

Returns

colorization color

See also

colorizeOn()

colorizeOn(self) → bool

Returns whether the effect will colorize a picture.

Return type

bool

Returns

True if colorization is enabled

See also

setColorizeOn()

See also

colorizeColor()

colorizeStrength(self) → int

Returns the strength used for colorizing a picture. This is only used if setColorizeOn() is set to True.

Return type

int

Returns

colorization strength, between 0 and 100

See also

colorizeOn()

See also

colorizeColor()

contrast(self) → int

Returns the contrast modification for the effect.

Return type

int

Returns

contrast value. Values are between -100 and 100, where 0 represents no change, negative values indicate less contrast and positive values indicate greater contrast

See also

setContrast()

create(map: Dict[str, str])QgsPaintEffect

Creates a new QgsColorEffect effect from a properties string map.

Parameters

map (Dict[str) – encoded properties string map

Return type

QgsPaintEffect

Returns

new QgsColorEffect

draw(self, context: QgsRenderContext)
Parameters

context (QgsRenderContext) –

drawSource(self, painter: QPainter)

Draws the source QPicture onto the specified painter. Handles scaling of the picture to account for the destination painter’s DPI.

Parameters

painter – destination painter

See also

source()

See also

sourceAsImage()

fixQPictureDpi(self, painter: QPainter)

Applies a workaround to a QPainter to avoid an issue with incorrect scaling when drawing QPictures. This may need to be called by derived classes prior to rendering results onto a painter.

Parameters

painter – destination painter

grayscaleMode(self) → QgsImageOperation.GrayscaleMode

Returns whether the effect will convert a picture to grayscale.

Return type

QgsImageOperation.GrayscaleMode

Returns

method for grayscale conversion

imageOffset(self, context: QgsRenderContext) → QPointF

Returns the offset which should be used when drawing the source image on to a destination render context.

Parameters

context – destination render context

Returns

point offset for image top left corner

See also

sourceAsImage()

opacity(self) → float

Returns the opacity for the effect.

Return type

float

Returns

opacity value between 0 and 1 inclusive, where 0 is fully transparent and 1 is fully opaque.

See also

setOpacity()

properties(self) → Dict[str, str]
Return type

Dict[str, str]

readProperties(self, props: Dict[str, str])
Parameters

props (Dict[str) –

saturation(self) → float

Returns the saturation modification for the effect.

Return type

float

Returns

saturation value. Values are between 0 and 2.0, where 1.0 represents no change, 0.0 represents totally desaturated (grayscale), and positive values indicate greater saturation

See also

setSaturation()

setBlendMode(self, mode: QPainter.CompositionMode)

Sets the blend mode for the effect

Parameters

mode (QPainter.CompositionMode) – blend mode used for drawing the effect on to a destination paint device

See also

blendMode()

setBrightness(self, brightness: int)

Sets the brightness modification for the effect.

Parameters

brightness (int) – Valid values are between -255 and 255, where 0 represents no change, negative values indicate darkening and positive values indicate lightening

See also

setBrightness()

setColorizeColor(self, colorizeColor: Union[QColor, Qt.GlobalColor, QGradient])

Sets the color used for colorizing a picture. This is only used if setColorizeOn() is set to True.

Parameters

colorizeColor (Union[QColor) – colorization color

See also

colorizeColor()

See also

setColorizeOn()

setColorizeOn(self, colorizeOn: bool)

Sets whether the effect should colorize a picture.

Parameters

colorizeOn (bool) – set to True to enable colorization

See also

colorizeOn()

setColorizeStrength(self, colorizeStrength: int)

Sets the strength for colorizing a picture. This is only used if setColorizeOn() is set to True.

Parameters

colorizeStrength (int) – colorization strength, between 0 and 100

See also

setColorizeOn()

setContrast(self, contrast: int)

Sets the contrast modification for the effect.

Parameters

contrast (int) – Valid values are between -100 and 100, where 0 represents no change, negative values indicate less contrast and positive values indicate greater contrast

See also

setContrast()

setGrayscaleMode(self, grayscaleMode: QgsImageOperation.GrayscaleMode)

Sets whether the effect should convert a picture to grayscale.

Parameters

grayscaleMode (QgsImageOperation.GrayscaleMode) – method for grayscale conversion

See also

grayscaleMode()

setOpacity(self, opacity: float)

Sets the opacity for the effect.

Parameters

opacity (float) – double between 0 and 1 inclusive, where 0 is fully transparent and 1 is fully opaque

See also

opacity()

setSaturation(self, saturation: float)

Sets the saturation modification for the effect.

Parameters

saturation (float) – Valid values are between 0 and 2.0, where 1.0 represents no change, 0.0 represents totally desaturated (grayscale), and positive values indicate greater saturation

See also

saturation()

source(self) → QPicture

Returns the source QPicture. The draw() member can utilize this when drawing the effect.

Returns

source QPicture

See also

drawSource()

See also

sourceAsImage()

sourceAsImage(self, context: QgsRenderContext) → QImage

Returns the source QPicture rendered to a new QImage. The draw() member can utilize this when drawing the effect. The image will be padded or cropped from the original source QPicture by the results of the boundingRect() method. The result is cached to speed up subsequent calls to sourceAsImage.

Returns

source QPicture rendered to an image

See also

drawSource()

See also

source()

See also

imageOffset()

See also

boundingRect()

type(self) → str
Return type

str