Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7553718
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: 嵌入式

2013-11-18 15:35:39

      程序启动画面一般用于显示软件信息(名称、作者、版权等)以及减少程序加载过程中的枯燥感。在Qt中,可以通过QSplashScreen类来为应用程序添加一个启动画面,它会在应用程序的主窗口出现前显示一个图片,并且可以在图片上显示想要输出的信息。 

下面是一个简单的例子:

点击(此处)折叠或打开

  1. #include <QApplication>
  2. #include <QTextEdit>
  3. #include <QSplashScreen> 

  4. int main(int argc, char *argv[])
  5. {
  6.     QApplication app(argc, argv);
  7.     QSplashScreen *splash = new QSplashScreen;
  8.     splash->setPixmap(QPixmap(":/images/splash.png"));
  9.     splash->show();
  10.     Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
  11.     splash->showMessage(QObject::tr("Setting up the main Window..."),
  12.                         topRight,
  13.                         Qt::red);
  14.   //  sleep(30);
  15.     QTextEdit *textEdit = new QTextEdit;
  16.     splash->showMessage(QObject::tr("Loading modules..."),
  17.                         topRight,
  18.                         Qt::blue);
  19.     QTest::qSleep(3000);
  20.     textEdit->show();
  21.     splash->finish(textEdit);
  22.     delete splash;
  23.     return app.exec();
  24. }

注意:

启动画面图片是通过setPixmap()来指定的,在这里图片是一个资源,因此,需要把图片添加到资源文件(.qrc)中;否则,看不到启动画面。 

阅读(1514) | 评论(0) | 转发(0) |
1

上一篇:QSettings

下一篇:QT程序打包发布 - 免安装

给主人留下些什么吧!~~