使用QSplashScreen 启动GIF动画 ,设置的3秒窗口延迟,GIF在三秒内是静止的,
等窗口初始化完成之后GIF才动
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPixmap pixmap(440,175);
QSplashScreen splash(pixmap);
QLabel *label=new QLabel(&splash);
QMovie *movie=new QMovie(":/test.gif");
label->setMovie(movie);
movie->start();
splash.show();
a.processEvents();
Widget w;
//w.show();
//splash.close();//测试注释掉了
return a.exec();
}
这样确实是不行的,只会静止。可以用计时器每帧更新画面:
#include <QApplication>
#include <QSplashScreen>
#include <QMovie>
#include <QTimer>
void UpdateGif(QSplashScreen *screen, QMovie *movie)
{
screen->setPixmap(movie->currentPixmap());
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPixmap pixmap(440, 175);
auto screen = new QSplashScreen(pixmap);
auto movie = new QMovie(":/test.gif");
movie->start();
auto timer = new QTimer(screen);
QTimer::connect(timer, &QTimer::timeout, [=]
{
UpdateGif(screen, movie);
});
timer->start();
screen->show();
return QApplication::exec();
}