(转载)QSplashScreen的用法
(转载)http://www.devdiv.com/qsplashscreen_-blog-1459-1264.html
许多应用程序在启动时显示一个画面。在程序启动很慢时,程序员用这种方法可以让
启动时间感觉不那么长,还有用这个画面满足市场的一些要求。给Qt 应用程序加一个启动
画面很简单,需要使用的类是QSplashScreen。
在窗口没有显示之前,QSplashScreen 显示一个图片,他还可以在图片上显示文字信息提
示用户当前程序初始化的进度。一般情况下,启动画面代码在main()函数中,加在调用
QApplication::exec()之前。
下面的一个程序的main()函数使用QSplashScreen 显示一个启动画面,同时显示加载的
模块信息和网络连接情况。
启动时间感觉不那么长,还有用这个画面满足市场的一些要求。给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("C:\\Img\\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(); }