QGraphicsEffect Class

The QGraphicsEffect class is the base class for all graphics effects. More...

Header: #include <QGraphicsEffect>
qmake: QT += widgets
Since: Qt 4.6
Inherits: QObject
Inherited By:

QGraphicsBlurEffect, QGraphicsColorizeEffect, QGraphicsDropShadowEffect, and QGraphicsOpacityEffect

This class was introduced in Qt 4.6.

Public Types

enum ChangeFlag { SourceAttached, SourceDetached, SourceBoundingRectChanged, SourceInvalidated }
enum PixmapPadMode { NoPad, PadToTransparentBorder, PadToEffectiveBoundingRect }

Properties

Public Functions

bool isEnabled() const

Public Slots

void setEnabled(bool enable)

Signals

void enabledChanged(bool enabled)

Detailed Description

Effects alter the appearance of elements by hooking into the rendering pipeline and operating between the source (e.g., a QGraphicsPixmapItem) and the destination device (e.g., QGraphicsView's viewport). Effects can be disabled by calling setEnabled(false). If effects are disabled, the source is rendered directly.

To add a visual effect to a QGraphicsItem, for example, you can use one of the standard effects, or alternately, create your own effect by creating a subclass of QGraphicsEffect. The effect can then be installed on the item using QGraphicsItem::setGraphicsEffect().

Qt provides the following standard effects:

For more information on how to use each effect, refer to the specific effect's documentation.

To create your own custom effect, create a subclass of QGraphicsEffect (or any other existing effects) and reimplement the virtual function draw(). This function is called whenever the effect needs to redraw. The draw() function takes the painter with which to draw as an argument. For more information, refer to the documentation for draw(). In the draw() function you can call sourcePixmap() to get a pixmap of the graphics effect source which you can then process.

If your effect changes, use update() to request for a redraw. If your custom effect changes the bounding rectangle of the source, e.g., a radial glow effect may need to apply an extra margin, you can reimplement the virtual boundingRectFor() function, and call updateBoundingRect() to notify the framework whenever this rectangle changes. The virtual sourceChanged() function is called to notify the effects that the source has changed in some way - e.g., if the source is a QGraphicsRectItem and its rectangle parameters have changed.

See also QGraphicsItem::setGraphicsEffect() and QWidget::setGraphicsEffect().

Member Type Documentation

enum QGraphicsEffect::ChangeFlag

This enum describes what has changed in QGraphicsEffectSource.

ConstantValueDescription
QGraphicsEffect::SourceAttached0x1The effect is installed on a source.
QGraphicsEffect::SourceDetached0x2The effect is uninstalled on a source.
QGraphicsEffect::SourceBoundingRectChanged0x4The bounding rect of the source has changed.
QGraphicsEffect::SourceInvalidated0x8The visual appearance of the source has changed.

enum QGraphicsEffect::PixmapPadMode

This enum describes how the pixmap returned from sourcePixmap should be padded.

ConstantValueDescription
QGraphicsEffect::NoPad0The pixmap should not receive any additional padding.
QGraphicsEffect::PadToTransparentBorder1The pixmap should be padded to ensure it has a completely transparent border.
QGraphicsEffect::PadToEffectiveBoundingRect2The pixmap should be padded to match the effective bounding rectangle of the effect.

Property Documentation

enabled : bool

This property holds whether the effect is enabled or not.

If an effect is disabled, the source will be rendered with as normal, with no interference from the effect. If the effect is enabled, the source will be rendered with the effect applied.

This property is enabled by default.

Using this property, you can disable certain effects on slow platforms, in order to ensure that the user interface is responsive.

Access functions:

bool isEnabled() const
void setEnabled(bool enable)

Notifier signal:

void enabledChanged(bool enabled)