程序启动画面一般用于显示软件信息(名称、作者、版权等)以及减少程序加载过程中的枯燥感。
在Qt中,可以通过QSplashScreen类来为应用程序添加一个启动画面,它会在应用程序的主窗口出现前显示一个图片,并且可以在图片上显示想要输出的信息。
下面是一个简单的例子:
#include
#include
#include
#include
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();
<