Qt5 程序启动画面动图效果
2333终于实现动图,先弄了一个窗口去掉标题栏假装就是启动画面了,还是那只萌萌的猫这次会动了!
基类用的是QWidget 类名称MainView
#ifndef MAINVIEW_H #define MAINVIEW_H #include <QWidget> #include <QGridLayout> #include <QPushButton> #include <windows.h> #include <QApplication> #include <QTimer> class MainView : public QWidget { Q_OBJECT public: explicit MainView(QWidget *parent = 0); QGridLayout *main; QPushButton *btn; signals: void signals_WakeupApp(); private slots: void slots_StopStartup(); void slots_WakeupApp(); private: bool startupIsOver; }; #endif // MAINVIEW_H
#include "MainView.h" #include <QDebug> MainView::MainView(QWidget *parent) : QWidget(parent) { startupIsOver = false; main = new QGridLayout(this); btn = new QPushButton(tr("Just Button")); main->addWidget(btn, 0, 0); connect(this, SIGNAL(signals_WakeupApp()), this, SLOT(slots_WakeupApp())); emit signals_WakeupApp(); Sleep(3000); } void MainView::slots_StopStartup() { startupIsOver = true; } void MainView::slots_WakeupApp() { QTimer t; connect(&t ,SIGNAL(timeout()), this, SLOT(slots_StopStartup())); t.start(5000); while(!startupIsOver) { QApplication::processEvents(); } }
#include <QApplication> #include <QPixmap> #include <QSplashScreen> #include <QLabel> #include <QMovie> #include "MainView.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); QMovie *movie; movie=new QMovie(":/new/prefix1/4"); QLabel *label=new QLabel("", 0); label->setWindowFlags(Qt::FramelessWindowHint); label->move(600,300); label->setMovie(movie); label->setScaledContents(true); movie->start(); label->show(); MainView w; w.show(); label->close(); return app.exec(); }