QT QSplashScreen 设置启动界面

    当启动程序时,有时候在程序启动的时候需要做长时间的准备工作,这时候为了增加用户体验,我们需要在启动过程中显示一幅图片,动画和一些提示性文字来告诉用户现在正在启动,以及启动到什么阶段了。增加了程序的友好度。

QT已经为我们提供了QSplashScreen类,用来在程序启动时候提供一些画面和提示性文字。

根据QT自带的例子可以更改一下:

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

    QPixmap pixmap(":/images/images/4.jpg");
    QSplashScreen splash(pixmap);
    splash.show();

    //启动第一阶段
    splash.showMessage(QStringLiteral("正在加载资源文件,请稍后……"), Qt::AlignHCenter|Qt::AlignBottom, Qt::red);
    QDateTime n=QDateTime::currentDateTime();
    QDateTime now;
    do{
        now=QDateTime::currentDateTime();
    } while (n.secsTo(now)<=3);//3为需要延时的秒数

    //启动第二阶段
    splash.showMessage(QStringLiteral("正在登录中,请稍后……"), Qt::AlignHCenter|Qt::AlignBottom, Qt::red);
    n=QDateTime::currentDateTime();
    now;
    do{
        now=QDateTime::currentDateTime();
    } while (n.secsTo(now)<=3);//3为需要延时的秒数

    MainWindow w;
    w.show();

    splash.finish(&w);

    return a.exec();
}



不过不幸的是,好像只能使用静态图片,并不能加载.gif图片,方法寻找中……



猜你喜欢

转载自blog.csdn.net/xiezhongyuan07/article/details/80272824