c++ - Qt SplashScreen w/ Fading Logo Not Running Animation -
i creating loading screen app , want implement 2 qlabels (background , overlay) in overlay glowing outline of background. want overlay fade in opacity (0.0 - 1.0) use qpropertyanimation windowopacity property label, nothing works this. here full source code.
main.cpp:
#include "mainwindow.h" #include "imagefade.h" #include <qapplication> #include <qsplashscreen> #include <qtimer> #include <qhboxlayout> #include <qlabel> int main(int argc, char *argv[]) { qapplication a(argc, argv); qsplashscreen *splashscreen = new qsplashscreen(); splashscreen->resize(500, 500); qpixmap bkgdimage(":/files/images/launch/launch.png"); qpixmap ovlyimage(":/files/images/launch/launch-glow.png"); imagefade *imagelabel= new imagefade(splashscreen); imagelabel->setbackgroundimage(bkgdimage); imagelabel->setoverlayimage(ovlyimage); imagelabel->startanimation(5000); splashscreen->show(); mainwindow w; qtimer::singleshot(2500, splashscreen, slot(close())); qtimer::singleshot(2500, &w, slot(show())); //w.show(); return a.exec(); }
imagefade.cpp:
#include "imagefade.h" #include <qdebug> imagefade::imagefade(qwidget *parent) : qwidget(parent) { bkgdlabel = new qlabel(); ovlylabel = new qlabel(); bkgdlabel->setgeometry(qrect(qpoint(0, 0), qsize(parent->size()))); ovlylabel->setgeometry(qrect(qpoint(0, 0), qsize(parent->size()))); fadeanimation = new qpropertyanimation(ovlylabel, "windowopacity"); fadeanimation->setloopcount(5); fadeanimation->setstartvalue(1.0); fadeanimation->setendvalue(0.0); fadeanimation->seteasingcurve(qeasingcurve::outquad); connect(fadeanimation, signal(statechanged(qabstractanimation::state,qabstractanimation::state)), this, slot(statechanged(qabstractanimation::state,qabstractanimation::state))); } imagefade::~imagefade() { //fadeanimation->stop(); } void imagefade::setbackgroundimage(qpixmap bkgdimg) { this->bkgdimg = bkgdimg; bkgdlabel->setpixmap(bkgdimg.scaled(size(), qt::keepaspectratio, qt::smoothtransformation)); } void imagefade::setoverlayimage(qpixmap ovlyimg) { this->ovlyimg = ovlyimg; ovlylabel->setpixmap(ovlyimg.scaled(size(), qt::keepaspectratio, qt::smoothtransformation)); } void imagefade::startanimation(int fadedelay) { fadeanimation->setduration(fadedelay); fadeanimation->start(qabstractanimation::deletewhenstopped); } void imagefade::stop() { fadeanimation->stop(); } void imagefade::statechanged(qabstractanimation::state state1, qabstractanimation::state state2) { qdebug() << state1 << state2; }
imagefade.h:
#ifndef imagefade_h #define imagefade_h #include <qwidget> #include <qlabel> #include <qlabel> #include <qpropertyanimation> class imagefade : public qwidget { q_object public: explicit imagefade(qwidget *parent = nullptr); ~imagefade(); void setbackgroundimage(qpixmap bkgdimg); void setoverlayimage(qpixmap ovlyimg); void startanimation(int fadedelay); void stop(); signals: public slots: void statechanged(qabstractanimation::state state1, qabstractanimation::state state2); private: qlabel *bkgdlabel; qlabel *ovlylabel; qpixmap bkgdimg; qpixmap ovlyimg; qpropertyanimation *fadeanimation; }; #endif // imagefade_h
i had same problem few days ago. can share code how hide/show label using animation.
qgraphicsopacityeffect *opacity; opacity = new qgraphicsopacityeffect("label_name"); ui->"label_name"->setgraphicseffect(opacity); qpropertyanimation *anim = new qpropertyanimation(opacity, "opacity"); anim->seteasingcurve(qeasingcurve::linear); anim->setstartvalue(1.0); anim->setendvalue(0.01); anim->setduration(1000); anim->start(qabstractanimation::deletewhenstopped);
this small example how hide qlabel using qpropertyanimation. can vise versa (show label) if set start value 0.01 , end value 1.0
Comments
Post a Comment