QT5 设置开机动态启动画面(gif与swf两种动画格式)

多数大型应用程序启动时都会在程序完全启动前显示一个启动画面,在程序完全启动后消失。

过程很简单,只是建立了一个基于Qt控制台的项目,文件也只有一个——"main.cpp"。

直接上代码,注意如果要播放Flash动画需要引入QAxWidget类,库文件有QAxContainer.lib,QAxServer.lib等。

 #include <QtGui>
 #include <QtGui/QApplication>
 #include <QTextCodec> 
 #include <QWidget>
 #include <ActiveQt/QAxWidget>
 #include <QTime>
 
 void gifplay(QLabel *label)
 {
     label->show();
 }

 void gifclose(QLabel *label)
 {
     label->close();
 }
 
 void flashplay(QAxWidget *flash)
 {
     flash->show();
 }
 
 void flashclose(QAxWidget *flash)
 {
     flash->close();
 }
 
 int main(int argc, char *argv[])
{
     QApplication a(argc, argv);
 
    QTextCodec *codec = QTextCodec::codecForName("GB2312"); //文本为GB2312编码
     QTextCodec::setCodecForLocale(codec);       //设置本地编码
     QTextCodec::setCodecForCStrings(codec);     //设置字符串编码
     QTextCodec::setCodecForTr(codec);
 
     QAxWidget *flash = new QAxWidget(0,0);      //QAxWidget使用的是ActiveX插件
     flash->resize(800,600);                    //设置该控件的初始大小
     flash->setControl(QString::fromUtf8("{d27cdb6e-ae6d-11cf-96b8-444553540000}")); //设定控制器
     flash->dynamicCall("LoadMovie(long,string)",0,"D:\\flash1.swf");   //
     flash->setWindowFlags(Qt::FramelessWindowHint);   //去除边框
     flashplay(flash);
     QTime t;
     t.start();
     while(t.elapsed()<5000)
     {
         QApplication::processEvents();
     }
     flashclose(flash);
 
     /*
     QMovie *movie;  
     movie = new QMovie("D:\\gif1.gif");  
     QLabel *label=new QLabel ("", 0);
     label->setGeometry( 300, 300, 500, 500 );  
     label->setMovie(movie);  
     label->setScaledContents(true);  
     movie->start();  
     gifplay(label);
     t.start();
     while(t.elapsed()<5000)
     {
         QApplication::processEvents();
     }
     gifclose(label);  
     */
 
     return a.exec();
 }

 

 

#include "mainwindow.h"
#include <QApplication>
#include <QSplashScreen>
#include <QTextEdit>
#include <QPixmap>
#include <QTest>       //需要在工程文件当中加入 QT += testlib

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QSplashScreen *splash = new QSplashScreen();
    splash->setPixmap(QPixmap(":/images/lubuntu_logo.png"));
    splash->show();

   a.processEvents();      //这句话必须加上,不加的话,无法实现效果。

    //QTest::qSleep(3000);

    splash->showMessage(QObject::tr("Loading modules..."),
                            Qt::AlignCenter,
                            Qt::blue);
    QTest::qSleep(6000);

    MainWindow w;
    w.show();
    splash->finish(&w);
    delete splash;

    return a.exec();
}

 

#include "mainwindow.h"
#include <QApplication>
#include <QPixmap>
#include <QSplashScreen>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    //  启动画面
    QPixmap pixmap("F:\\MyCode\\dcq.jpg");   //设置启动画面
    QSplashScreen splash(pixmap);
    splash.show();   //显示此启动图像
    a.processEvents();   //使得程序在显示启动画面的同时还能够响应其他事件

    MainWindow w;
    w.show();     //等待主程序初始化完成之后

    splash.finish(&w);  //程序启动画面完成
    return a.exec();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值