Fading the picture in
When the user opens a picture, we want to fade in the image by playing with its opacity. The classes QLabel
or QWidget
do not provide an opacity property. However, we can add a visual effect to any QWidget
using a QGraphicsEffect
. For this animation, we will use QGraphicsOpacityEffect
to provide an opacity
property.
Here is a schema to describe the role of each one:
In our case, the QWidget
class is our QLabel
and the QGraphicsEffect
class is QGraphicsOpacityEffect
. Qt provides the Graphics Effect system to alter the rendering of a QWidget
class. The abstract class QGraphicsEffect
has a pure virtual method draw()
that is implemented by each graphics effect.
We can now update the MainWindow.h
according to the next snippet:
#include <QPropertyAnimation> #include <QGraphicsOpacityEffect> class MainWindow : public QMainWindow { ... private: ... void initAnimations(); private: ... QPropertyAnimation mLoadPictureAnimation; QGraphicsOpacityEffect...