The QGraphicsEffect class is the base class for all graphics effects. More...
Header: | #include |
qmake: | QT += widgets |
Since: | Qt 4.6 |
Inherits: | QObject |
Inherited By: | QGraphicsBlurEffect, QGraphicsColorizeEffect, QGraphicsDropShadowEffect, and QGraphicsOpacityEffect |
@Christian-Ehrlicher My base class calls a virtual function which is meant to be overridden by platform specific code. That code could be Qt, or objective c, or whatever. In the case of Qt, rather than overriding the virtual function to then just emit another signal, I wanted to make that override the actual signal.
Public Types
enum | ChangeFlag { SourceAttached, SourceDetached, SourceBoundingRectChanged, SourceInvalidated } |
flags | ChangeFlags |
enum | PixmapPadMode { NoPad, PadToTransparentBorder, PadToEffectiveBoundingRect } |
Properties
- If i create a class from a base class with virtual slots, the slots never get called with the new connect-flavour. If i use the old connect-syntax, the slot gets called. What could be the problem? @ class BaseClass: public QObject public slots: virt.
- If the plugin metadata contains InputMethod field defining an input method name, Qt Virtual Keyboard will call registerTypes for registering the input method as QML type. The type must be registered with a uri if the input method is used by the default keyboard layouts.
- enabled : bool
- 1 property inherited from QObject
Public Functions
QGraphicsEffect(QObject *parent = Q_NULLPTR) | |
virtual | ~QGraphicsEffect() |
QRectF | boundingRect() const |
virtual QRectF | boundingRectFor(const QRectF &rect) const |
bool | isEnabled() const |
- 32 public functions inherited from QObject
Public Slots
- 1 public slot inherited from QObject
Signals
void | enabledChanged(bool enabled) |
- 2 signals inherited from QObject
Protected Functions
virtual void | draw(QPainter *painter) = 0 |
void | drawSource(QPainter *painter) |
QRectF | sourceBoundingRect(Qt::CoordinateSystem system = Qt::LogicalCoordinates) const |
virtual void | sourceChanged(ChangeFlags flags) |
bool | sourceIsPixmap() const |
QPixmap | sourcePixmap(Qt::CoordinateSystem system = Qt::LogicalCoordinates, QPoint *offset = Q_NULLPTR, PixmapPadMode mode = PadToEffectiveBoundingRect) const |
void | updateBoundingRect() |
- 9 protected functions inherited from QObject
Additional Inherited Members
- 11 static public members inherited from QObject
Detailed Description
The QGraphicsEffect class is the base class for all graphics effects.
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:
- QGraphicsBlurEffect - blurs the item by a given radius
- QGraphicsDropShadowEffect - renders a dropshadow behind the item
- QGraphicsColorizeEffect - renders the item in shades of any given color
- QGraphicsOpacityEffect - renders the item with an opacity
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 documenation 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
flags QGraphicsEffect::ChangeFlags
This enum describes what has changed in QGraphicsEffectSource.
Constant | Value | Description |
---|---|---|
QGraphicsEffect::SourceAttached | 0x1 | The effect is installed on a source. |
QGraphicsEffect::SourceDetached | 0x2 | The effect is uninstalled on a source. |
QGraphicsEffect::SourceBoundingRectChanged | 0x4 | The bounding rect of the source has changed. |
QGraphicsEffect::SourceInvalidated | 0x8 | The visual appearance of the source has changed. |
The ChangeFlags type is a typedef for QFlags. It stores an OR combination of ChangeFlag values.
enum QGraphicsEffect::PixmapPadMode
This enum describes how the pixmap returned from sourcePixmap should be padded.
Constant | Value | Description |
---|---|---|
QGraphicsEffect::NoPad | 0 | The pixmap should not receive any additional padding. |
QGraphicsEffect::PadToTransparentBorder | 1 | The pixmap should be padded to ensure it has a completely transparent border. |
QGraphicsEffect::PadToEffectiveBoundingRect | 2 | The 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:
Member Function Documentation
QGraphicsEffect::QGraphicsEffect(QObject *parent = Q_NULLPTR)
Constructs a new QGraphicsEffect instance having the specified parent.
[virtual]
QGraphicsEffect::~QGraphicsEffect()
Removes the effect from the source, and destroys the graphics effect.
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() and updateBoundingRect().
[virtual]
QRectF QGraphicsEffect::boundingRectFor(const QRectF &rect) const
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().
[pure virtual protected]
void QGraphicsEffect::draw(QPainter *painter)
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.
[protected]
void QGraphicsEffect::drawSource(QPainter *painter)
Draws the source directly using the given painter.
This function should only be called from QGraphicsEffect::draw().
For example:
See also QGraphicsEffect::draw().
[signal]
void QGraphicsEffect::enabledChanged(boolenabled)
This signal is emitted whenever the effect is enabled or disabled. The enabled parameter holds the effects's new enabled state.
Note: Notifier signal for property enabled.
See also isEnabled().
[protected]
QRectF QGraphicsEffect::sourceBoundingRect(Qt::CoordinateSystemsystem = Qt::LogicalCoordinates) const
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().
[virtual protected]
void QGraphicsEffect::sourceChanged(ChangeFlagsflags)
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.
[protected]
bool QGraphicsEffect::sourceIsPixmap() const
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.
[protected]
QPixmap QGraphicsEffect::sourcePixmap(Qt::CoordinateSystemsystem = Qt::LogicalCoordinates, QPoint *offset = Q_NULLPTR, PixmapPadModemode = PadToEffectiveBoundingRect) const
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() and boundingRect().
[slot]
void QGraphicsEffect::update()
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().
[protected]
void QGraphicsEffect::updateBoundingRect()
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(), and sourceBoundingRect().
© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.
Hello.
I want to write a small tool and like to separate the business logic from the GUI so I can easily make and use different GUIs.
Therefore I've made a class which contains the business logic called AppCore. The GUI class(es) are called MainWindow.
My idea is to pass the constructor of the AppCore a reference to the GUI so the constructor of the AppCore can connect the AppCore singals to the GUI slots and vice versa.
But to make it flexible I don't want to have the actual GUI as type of the parameter but an Interface (pure virtual class) called IGui which the GUI inherits from.
@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
AppCore *appCore;
MainWindow w;
Qt provides the following standard effects:
- QGraphicsBlurEffect - blurs the item by a given radius
- QGraphicsDropShadowEffect - renders a dropshadow behind the item
- QGraphicsColorizeEffect - renders the item in shades of any given color
- QGraphicsOpacityEffect - renders the item with an opacity
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 documenation 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
flags QGraphicsEffect::ChangeFlags
This enum describes what has changed in QGraphicsEffectSource.
Constant | Value | Description |
---|---|---|
QGraphicsEffect::SourceAttached | 0x1 | The effect is installed on a source. |
QGraphicsEffect::SourceDetached | 0x2 | The effect is uninstalled on a source. |
QGraphicsEffect::SourceBoundingRectChanged | 0x4 | The bounding rect of the source has changed. |
QGraphicsEffect::SourceInvalidated | 0x8 | The visual appearance of the source has changed. |
The ChangeFlags type is a typedef for QFlags. It stores an OR combination of ChangeFlag values.
enum QGraphicsEffect::PixmapPadMode
This enum describes how the pixmap returned from sourcePixmap should be padded.
Constant | Value | Description |
---|---|---|
QGraphicsEffect::NoPad | 0 | The pixmap should not receive any additional padding. |
QGraphicsEffect::PadToTransparentBorder | 1 | The pixmap should be padded to ensure it has a completely transparent border. |
QGraphicsEffect::PadToEffectiveBoundingRect | 2 | The 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:
Member Function Documentation
QGraphicsEffect::QGraphicsEffect(QObject *parent = Q_NULLPTR)
Constructs a new QGraphicsEffect instance having the specified parent.
[virtual]
QGraphicsEffect::~QGraphicsEffect()
Removes the effect from the source, and destroys the graphics effect.
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() and updateBoundingRect().
[virtual]
QRectF QGraphicsEffect::boundingRectFor(const QRectF &rect) const
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().
[pure virtual protected]
void QGraphicsEffect::draw(QPainter *painter)
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.
[protected]
void QGraphicsEffect::drawSource(QPainter *painter)
Draws the source directly using the given painter.
This function should only be called from QGraphicsEffect::draw().
For example:
See also QGraphicsEffect::draw().
[signal]
void QGraphicsEffect::enabledChanged(boolenabled)
This signal is emitted whenever the effect is enabled or disabled. The enabled parameter holds the effects's new enabled state.
Note: Notifier signal for property enabled.
See also isEnabled().
[protected]
QRectF QGraphicsEffect::sourceBoundingRect(Qt::CoordinateSystemsystem = Qt::LogicalCoordinates) const
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().
[virtual protected]
void QGraphicsEffect::sourceChanged(ChangeFlagsflags)
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.
[protected]
bool QGraphicsEffect::sourceIsPixmap() const
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.
[protected]
QPixmap QGraphicsEffect::sourcePixmap(Qt::CoordinateSystemsystem = Qt::LogicalCoordinates, QPoint *offset = Q_NULLPTR, PixmapPadModemode = PadToEffectiveBoundingRect) const
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() and boundingRect().
[slot]
void QGraphicsEffect::update()
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().
[protected]
void QGraphicsEffect::updateBoundingRect()
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(), and sourceBoundingRect().
© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.
Hello.
I want to write a small tool and like to separate the business logic from the GUI so I can easily make and use different GUIs.
Therefore I've made a class which contains the business logic called AppCore. The GUI class(es) are called MainWindow.
My idea is to pass the constructor of the AppCore a reference to the GUI so the constructor of the AppCore can connect the AppCore singals to the GUI slots and vice versa.
But to make it flexible I don't want to have the actual GUI as type of the parameter but an Interface (pure virtual class) called IGui which the GUI inherits from.
@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
AppCore *appCore;
MainWindow w;
appCore = new AppCore(&w);
w.show();
return a.exec();
}
class IGui
{
public slots:
virtual void slot() = 0;
};
class MainWindow : public QMainWindow, public IGui
{
Q_OBJECT
};
class AppCore : public QObject
{
Q_OBJECT
}
AppCore::AppCore(IGui *gui, QObject *parent) :
QObject(parent)
{
connect(gui, SIGNAL(signal()),
this, SLOT(onSingal()));
}@
But when I try to compile I get errors:
[quote]
AppCore.cpp: In constructor 'AppCore::AppCore(IGui*, QObject*)':
AppCore.cpp:9: error: no matching function for call to 'AppCore::connect(IGui*&, const char [10], AppCore* const, const char [12])'
c:QtSDKDesktopQt4.8.1mingwincludeQtCore/qobject.h:204: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
c:QtSDKDesktopQt4.8.1mingwincludeQtCore/qobject.h:217: note: static bool QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
c:QtSDKDesktopQt4.8.1mingwincludeQtCore/qobject.h:337: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
AppCore.cpp:12: error: no matching function for call to 'AppCore::connect(AppCore* const, const char [10], IGui*&, const char [8])'
c:QtSDKDesktopQt4.8.1mingwincludeQtCore/qobject.h:204: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
c:QtSDKDesktopQt4.8.1mingwincludeQtCore/qobject.h:217: note: static bool QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
c:QtSDKDesktopQt4.8.1mingwincludeQtCore/qobject.h:337: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const[/quote]
If I let IGui derive from QObject I get this errors:
[quote]
releasemoc_MainWindow.cpp: In static member function 'static void MainWindow::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)':
releasemoc_MainWindow.cpp:52: error: 'QObject' is an ambiguous base of 'MainWindow'
releasemoc_MainWindow.cpp: In member function 'virtual const QMetaObject* MainWindow::metaObject() const':
releasemoc_MainWindow.cpp:78: error: 'QObject' is an ambiguous base of 'MainWindow'
releasemoc_MainWindow.cpp:78: error: 'QObject' is an ambiguous base of 'MainWindow'
releasemoc_MainWindow.cpp: In member function 'virtual int MainWindow::qt_metacall(QMetaObject::Call, int, void**)':
releasemoc_MainWindow.cpp:98: error: 'QObject' is an ambiguous base of 'MainWindow'
releasemoc_MainWindow.cpp: In member function 'virtual void MainWindow::signal()':
releasemoc_MainWindow.cpp:107: error: 'QObject' is an ambiguous base of 'MainWindow'
[/quote]
Qt Slot Virtual Function Cheat
How do I have to do it right?