QtBase  v6.3.1
Public Types | Public Slots | Signals | Public Member Functions | Protected Member Functions | Properties | Friends | List of all members
QGraphicsEffect Class Referenceabstract

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

#include <qgraphicseffect.h>

Inheritance diagram for QGraphicsEffect:
Inheritance graph
[legend]
Collaboration diagram for QGraphicsEffect:
Collaboration graph
[legend]

Public Types

enum  ChangeFlag { SourceAttached = 0x1 , SourceDetached = 0x2 , SourceBoundingRectChanged = 0x4 , SourceInvalidated = 0x8 }
 
enum  PixmapPadMode { NoPad , PadToTransparentBorder , PadToEffectiveBoundingRect }
 

Public Slots

void setEnabled (bool enable)
 
void update ()
 
- Public Slots inherited from QObject
void deleteLater ()
 

Signals

void enabledChanged (bool enabled)
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 

Public Member Functions

 QGraphicsEffect (QObject *parent=nullptr)
 
virtual ~QGraphicsEffect ()
 
virtual QRectF boundingRectFor (const QRectF &sourceRect) const
 
QRectF boundingRect () const
 
bool isEnabled () const
 
QGraphicsEffectSourcesource () const
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 
virtual ~QObject ()
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const
 
void setObjectName (const QString &name)
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 
bool isWindowType () const
 
bool signalsBlocked () const noexcept
 
bool blockSignals (bool b) noexcept
 
QThreadthread () const
 
void moveToThread (QThread *thread)
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 
template<typename T >
T findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
const QObjectListchildren () const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 
void dumpObjectInfo () const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 
bool inherits (const char *classname) const
 

Protected Member Functions

 QGraphicsEffect (QGraphicsEffectPrivate &d, QObject *parent=nullptr)
 
virtual void draw (QPainter *painter)=0
 
virtual void sourceChanged (ChangeFlags flags)
 
void updateBoundingRect ()
 
bool sourceIsPixmap () const
 
QRectF sourceBoundingRect (Qt::CoordinateSystem system=Qt::LogicalCoordinates) const
 
void drawSource (QPainter *painter)
 
QPixmap sourcePixmap (Qt::CoordinateSystem system=Qt::LogicalCoordinates, QPoint *offset=nullptr, PixmapPadMode mode=PadToEffectiveBoundingRect) const
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 

Properties

bool enabled
 whether the effect is enabled or not. More...
 
- Properties inherited from QObject
QString objectName
 the name of this object More...
 

Friends

class QGraphicsItem
 
class QGraphicsItemPrivate
 
class QGraphicsScenePrivate
 
class QWidget
 
class QWidgetPrivate
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 

Detailed Description

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

Since
4.6

\inmodule QtWidgets

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:

\list

\table \row

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(), QWidget::setGraphicsEffect()

Definition at line 62 of file qgraphicseffect.h.

Member Enumeration Documentation

◆ ChangeFlag

This enum describes what has changed in QGraphicsEffectSource.

\value SourceAttached The effect is installed on a source. \value SourceDetached The effect is uninstalled on a source. \value SourceBoundingRectChanged The bounding rect of the source has changed. \value SourceInvalidated The visual appearance of the source has changed.

Enumerator
SourceAttached 
SourceDetached 
SourceBoundingRectChanged 
SourceInvalidated 

Definition at line 67 of file qgraphicseffect.h.

◆ PixmapPadMode

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

\value NoPad The pixmap should not receive any additional padding. \value PadToTransparentBorder The pixmap should be padded to ensure it has a completely transparent border. \value PadToEffectiveBoundingRect The pixmap should be padded to match the effective bounding rectangle of the effect.

Enumerator
NoPad 
PadToTransparentBorder 
PadToEffectiveBoundingRect 

Definition at line 76 of file qgraphicseffect.h.

Constructor & Destructor Documentation

◆ QGraphicsEffect() [1/2]

QGraphicsEffect::QGraphicsEffect ( QObject parent = nullptr)

Constructs a new QGraphicsEffect instance having the specified parent.

Definition at line 399 of file qgraphicseffect.cpp.

◆ ~QGraphicsEffect()

QGraphicsEffect::~QGraphicsEffect ( )
virtual

Removes the effect from the source, and destroys the graphics effect.

Definition at line 415 of file qgraphicseffect.cpp.

◆ QGraphicsEffect() [2/2]

QGraphicsEffect::QGraphicsEffect ( QGraphicsEffectPrivate d,
QObject parent = nullptr 
)
protected

Definition at line 407 of file qgraphicseffect.cpp.

Member Function Documentation

◆ boundingRect()

QRectF QGraphicsEffect::boundingRect ( ) const

Returns the effective bounding rectangle for this effect, i.e., the bounding rectangle of the source in device coordinates, adjusted by any margins applied by the effect itself.

See also
boundingRectFor(), updateBoundingRect()

Definition at line 428 of file qgraphicseffect.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ boundingRectFor()

QRectF QGraphicsEffect::boundingRectFor ( const QRectF rect) const
virtual

Returns the effective bounding rectangle for this effect, given the provided rect in the device coordinates. When writing you own custom effect, you must call updateBoundingRect() whenever any parameters are changed that may cause this this function to return a different value.

See also
sourceBoundingRect()

Reimplemented in PaddingEffect, TestGraphicsEffect, CustomEffect, DeviceEffect, PixmapItemEffect, CustomEffect, QGraphicsDropShadowEffect, and QGraphicsBlurEffect.

Definition at line 445 of file qgraphicseffect.cpp.

Here is the caller graph for this function:

◆ draw()

void QGraphicsEffect::draw ( QPainter painter)
protectedpure virtual

This pure virtual function draws the effect and is called whenever the source needs to be drawn.

Reimplement this function in a QGraphicsEffect subclass to provide the effect's drawing implementation, using painter.

For example:

This function should not be called explicitly by the user, since it is meant for reimplementation purposes only.

Implemented in TestGraphicsEffect, CustomEffect, DeviceEffect, PixmapItemEffect, CustomEffect, QGraphicsOpacityEffect, QGraphicsDropShadowEffect, QGraphicsBlurEffect, QGraphicsColorizeEffect, BlurEffect, ListItemCache, and PaddingEffect.

Here is the caller graph for this function:

◆ drawSource()

void QGraphicsEffect::drawSource ( QPainter painter)
protected

Draws the source directly using the given painter.

This function should only be called from QGraphicsEffect::draw().

For example:

See also
QGraphicsEffect::draw()

Definition at line 251 of file qgraphicseffect.cpp.

Here is the caller graph for this function:

◆ enabledChanged

void QGraphicsEffect::enabledChanged ( bool  enabled)
signal

This signal is emitted whenever the effect is enabled or disabled. The enabled parameter holds the effects's new enabled state.

See also
isEnabled()
Here is the caller graph for this function:

◆ isEnabled()

bool QGraphicsEffect::isEnabled ( ) const

Definition at line 463 of file qgraphicseffect.cpp.

Here is the caller graph for this function:

◆ setEnabled

void QGraphicsEffect::setEnabled ( bool  enable)
slot

Definition at line 469 of file qgraphicseffect.cpp.

◆ source()

QGraphicsEffectSource * QGraphicsEffect::source ( ) const

Definition at line 513 of file qgraphicseffect.cpp.

Here is the caller graph for this function:

◆ sourceBoundingRect()

QRectF QGraphicsEffect::sourceBoundingRect ( Qt::CoordinateSystem  system = Qt::LogicalCoordinates) const
protected

Returns the bounding rectangle of the source mapped to the given system.

Calling this function with Qt::DeviceCoordinates outside of QGraphicsEffect::draw() will give undefined results, as there is no device context available.

See also
draw()

Definition at line 171 of file qgraphicseffect.cpp.

Here is the caller graph for this function:

◆ sourceChanged()

void QGraphicsEffect::sourceChanged ( ChangeFlags  flags)
protectedvirtual

This virtual function is called by QGraphicsEffect to notify the effect that the source has changed. If the effect applies any cache, then this cache must be purged in order to reflect the new appearance of the source.

The flags describes what has changed.

Reimplemented in CustomEffect, and ListItemCache.

Definition at line 588 of file qgraphicseffect.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sourceIsPixmap()

bool QGraphicsEffect::sourceIsPixmap ( ) const
protected

Returns true if the source effectively is a pixmap, e.g., a QGraphicsPixmapItem.

This function is useful for optimization purposes. For instance, there's no point in drawing the source in device coordinates to avoid pixmap scaling if this function returns true - the source pixmap will be scaled anyways.

Definition at line 291 of file qgraphicseffect.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sourcePixmap()

QPixmap QGraphicsEffect::sourcePixmap ( Qt::CoordinateSystem  system = Qt::LogicalCoordinates,
QPoint offset = nullptr,
QGraphicsEffect::PixmapPadMode  mode = PadToEffectiveBoundingRect 
) const
protected

Returns a pixmap with the source painted into it.

The system specifies which coordinate system to be used for the source. The optional offset parameter returns the offset where the pixmap should be painted at using the current painter. For control on how the pixmap is padded use the mode parameter.

The returned pixmap is clipped to the current painter's device rectangle when system is Qt::DeviceCoordinates.

Calling this function with Qt::DeviceCoordinates outside of QGraphicsEffect::draw() will give undefined results, as there is no device context available.

See also
draw(), boundingRect()

Definition at line 366 of file qgraphicseffect.cpp.

Here is the caller graph for this function:

◆ update

void QGraphicsEffect::update ( )
slot

Schedules a redraw of the effect. Call this function whenever the effect needs to be redrawn. This function does not trigger a redraw of the source.

See also
updateBoundingRect()

Definition at line 498 of file qgraphicseffect.cpp.

Here is the caller graph for this function:

◆ updateBoundingRect()

void QGraphicsEffect::updateBoundingRect ( )
protected

This function notifies the effect framework when the effect's bounding rectangle has changed. As a custom effect author, you must call this function whenever you change any parameters that will cause the virtual boundingRectFor() function to return a different value.

This function will call update() if this is necessary.

See also
boundingRectFor(), boundingRect(), sourceBoundingRect()

Definition at line 529 of file qgraphicseffect.cpp.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ QGraphicsItem

friend class QGraphicsItem
friend

Definition at line 113 of file qgraphicseffect.h.

◆ QGraphicsItemPrivate

friend class QGraphicsItemPrivate
friend

Definition at line 114 of file qgraphicseffect.h.

◆ QGraphicsScenePrivate

friend class QGraphicsScenePrivate
friend

Definition at line 115 of file qgraphicseffect.h.

◆ QWidget

friend class QWidget
friend

Definition at line 116 of file qgraphicseffect.h.

◆ QWidgetPrivate

friend class QWidgetPrivate
friend

Definition at line 117 of file qgraphicseffect.h.

Property Documentation

◆ enabled

QGraphicsEffect::enabled
readwrite

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.

Definition at line 280 of file qgraphicseffect.h.


The documentation for this class was generated from the following files: