QgsShadowEffect class

Base class for paint effects which offset, blurred shadows.

Base classes

class QgsPaintEffect
Base class for visual effects which can be applied to QPicture drawings.

Derived classes

class QgsDropShadowEffect
A paint effect which draws an offset and optionally blurred drop shadow.
class QgsInnerShadowEffect
A paint effect which draws an offset and optionally blurred drop shadow within a picture.

Public functions

auto blendMode() const -> QPainter::CompositionMode
Returns the blend mode for the effect.
auto blurLevel() const -> int
Returns the blur level (strength) for the shadow.
auto color() const -> QColor
Returns the color used for the shadow.
auto offsetAngle() const -> int
Returns the angle used for offsetting the shadow.
auto offsetDistance() const -> double
Returns the distance used for offsetting the shadow.
auto offsetMapUnitScale() const -> const QgsMapUnitScale&
Returns the map unit scale used for the shadow offset distance.
auto offsetUnit() const -> QgsUnitTypes::RenderUnit
Returns the units used for the shadow offset distance.
auto opacity() const -> double
Returns the opacity for the effect.
auto properties() const -> QgsStringMap override
Returns the properties describing the paint effect encoded in a string format.
void readProperties(const QgsStringMap& props) override
Reads a string map of an effect's properties and restores the effect to the state described by the properties map.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blend mode for the effect.
void setBlurLevel(const int level)
Sets blur level (strength) for the shadow.
void setColor(const QColor& color)
Sets the color for the shadow.
void setOffsetAngle(const int angle)
Sets the angle for offsetting the shadow.
void setOffsetDistance(const double distance)
Sets the distance for offsetting the shadow.
void setOffsetMapUnitScale(const QgsMapUnitScale& scale)
Sets the map unit scale used for the shadow offset distance.
void setOffsetUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units used for the shadow offset distance.
void setOpacity(const double opacity)
Sets the opacity for the effect.

Protected functions

auto boundingRect(const QRectF& rect, const QgsRenderContext& context) const -> QRectF override
Returns the bounding rect required for drawing the effect.
void draw(QgsRenderContext& context) override
Handles drawing of the effect's result on to the specified render context.
auto exteriorShadow() const -> bool pure virtual
Specifies whether the shadow is drawn outside the picture or within the picture.

Function documentation

QPainter::CompositionMode QgsShadowEffect::blendMode() const

Returns the blend mode for the effect.

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

int QgsShadowEffect::blurLevel() const

Returns the blur level (strength) for the shadow.

Returns blur level. Value will be between 0 and 16, with larger values indicating greater blur strength.

QColor QgsShadowEffect::color() const

Returns the color used for the shadow.

Returns shadow color

int QgsShadowEffect::offsetAngle() const

Returns the angle used for offsetting the shadow.

Returns offset angle in degrees clockwise from North

double QgsShadowEffect::offsetDistance() const

Returns the distance used for offsetting the shadow.

Returns offset distance. Distance units are retrieved via offsetUnit()

const QgsMapUnitScale& QgsShadowEffect::offsetMapUnitScale() const

Returns the map unit scale used for the shadow offset distance.

Returns map unit scale for offset distance

QgsUnitTypes::RenderUnit QgsShadowEffect::offsetUnit() const

Returns the units used for the shadow offset distance.

Returns units for offset distance

double QgsShadowEffect::opacity() const

Returns the opacity for the effect.

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

QgsStringMap QgsShadowEffect::properties() const override

Returns the properties describing the paint effect encoded in a string format.

Returns string map of properties, in the form property key, value

void QgsShadowEffect::readProperties(const QgsStringMap& props) override

Reads a string map of an effect's properties and restores the effect to the state described by the properties map.

Parameters
props effect properties encoded in a string map

void QgsShadowEffect::setBlendMode(const QPainter::CompositionMode mode)

Sets the blend mode for the effect.

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

void QgsShadowEffect::setBlurLevel(const int level)

Sets blur level (strength) for the shadow.

Parameters
level blur level. Values between 0 and 16 are valid, with larger values indicating greater blur strength.

void QgsShadowEffect::setColor(const QColor& color)

Sets the color for the shadow.

Parameters
color shadow color

void QgsShadowEffect::setOffsetAngle(const int angle)

Sets the angle for offsetting the shadow.

Parameters
angle offset angle in degrees clockwise from North

void QgsShadowEffect::setOffsetDistance(const double distance)

Sets the distance for offsetting the shadow.

Parameters
distance offset distance. Units are specified via setOffsetUnit()

void QgsShadowEffect::setOffsetMapUnitScale(const QgsMapUnitScale& scale)

Sets the map unit scale used for the shadow offset distance.

Parameters
scale map unit scale for offset distance

void QgsShadowEffect::setOffsetUnit(const QgsUnitTypes::RenderUnit unit)

Sets the units used for the shadow offset distance.

Parameters
unit units for offset distance

void QgsShadowEffect::setOpacity(const double opacity)

Sets the opacity for the effect.

Parameters
opacity double between 0 and 1 inclusive, where 0 is fully transparent and 1 is fully opaque

QRectF QgsShadowEffect::boundingRect(const QRectF& rect, const QgsRenderContext& context) const override protected

Returns the bounding rect required for drawing the effect.

Parameters
rect original source bounding rect
context destination render context
Returns modified bounding rect

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

void QgsShadowEffect::draw(QgsRenderContext& context) override protected

Handles drawing of the effect's result on to the specified render context.

Parameters
context destination render context

Derived classes must reimplement this method to apply any transformations to the source QPicture and draw the result using the context's painter.

bool QgsShadowEffect::exteriorShadow() const pure virtual protected

Specifies whether the shadow is drawn outside the picture or within the picture.

Returns true if shadow is to be drawn outside the picture, or false to draw shadow within the picture