现在的位置: 首页 > 综合 > 正文

启动画面(Splash Screens)

2013年01月26日 ⁄ 综合 ⁄ 共 1045字 ⁄ 字号 评论关闭

  启动画面(Splash Screens)

启动画面(Splash Screens)

 许多应用程序在启动时显示一个画面。在程序启动很慢时,程序员用这种方法可以让启动时间感觉不那么长,还有用这个画面满足市场的一些要求。给Qt应用程序加一个启动画面很简单,需要使用的类是QSplashScreen。

在窗口没有显示之前,QSplashScreen显示一个图片,他还可以在图片上显示文字信息提示用户当前程序初始化的进度。一般情况下,启动画面代码在main()函数中,加在调用QApplication::exec()之前。
下面的一个程序的main()函数使用QSplashScreen显示一个启动画面,同时显示加载的模块信息和网络连接情况。
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QSplashScreen *splash = new QSplashScreen;
    splash->setPixmap(QPixmap(":/images/splash.png"));
    splash->show();
    Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
    splash->showMessage(QObject::tr("Setting up the main window..."),
                        topRight, Qt::white);
    MainWindow mainWin;
    splash->showMessage(QObject::tr("Loading modules..."),
                        topRight, Qt::white);
    loadModules();
    splash->showMessage(QObject::tr("Establishing connections..."),
                        topRight, Qt::white);
    establishConnections();
    mainWin.show();
    splash->finish(&mainWin);
    delete splash;
    return app.exec();
}
Spreadsheet程序的用户界面部分我们已经完成了。在下一章中我们将会实现表格的核心功能。

抱歉!评论已关闭.