日志
Qt_程序启动画面
2012-03-30 16:27
Qt_程序启动画面
转自http://blog.csdn.net/gohome520/article/details/6569000 程序启动画面一般用于显示软件信息(名称、作者、版权等)以及减少程序加载过程中的枯燥感。 在Qt中,可以通过QSplashScreen类来为应用程序添加一个启动画面,它会在应用程序的主窗口出现前显示一个图片,并且可以在图片上显示想要输出的信息。 下面是一个简单的例子: view plain #include <QApplication> #include <QTextEdit> #include <QSplashScreen> #include <QtTest> 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::red); QTest::qSleep(3000); QTextEdit *textEdit = new QTextEdit; splash>showMessage(QObject::tr("Loading modules..."), topRight, Qt::blue); QTest::qSleep(3000); textEdit->show(); splash->finish(textEdit); delete splash; return app.exec(); } 注意1: 启动画面图片是通过setPixmap()来指定的,在这里图片是一个资源,因此,需要把图片添加到资源文件(.qrc)中;否则,看不到启动画面。 注意2: 在例子程序中,使用了QTest::qSleep()函数,因此,需要包含头文件<QTest>,并在.pro文件中,加入 CONFIG += qtestlib |
下一篇: Qt的进度条实现
上一篇: 通过Qt样式表定制程序外观
pinkyuanxue:是吗?我是看到了,就随手记了一下,省得用的时候再去找了。
2012-03-30 17:53