Qt_程式啟動畫面

來源:互聯網
上載者:User

程式啟動畫面一般用於顯示軟體資訊(名稱、作者、著作權等)以及減少程式載入過程中的枯燥感。

在Qt中,可以通過QSplashScreen類來為應用程式添加一個啟動畫面,它會在應用程式的主視窗出現前顯示一個圖片,並且可以在圖片上顯示想要輸出的資訊。

 

下面是一個簡單的例子:

#include <QApplication><br />#include <QTextEdit><br />#include <QSplashScreen><br />#include <QtTest><br />int main(int argc, char *argv[])<br />{<br /> QApplication app(argc, argv);<br /> QSplashScreen *splash = new QSplashScreen;<br /> splash->setPixmap(QPixmap(":/images/splash.png"));<br /> splash->show();<br /> Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;<br /> splash->showMessage(QObject::tr("Setting up the main Window..."),<br /> topRight,<br /> Qt::red);<br /> QTest::qSleep(3000);<br /> QTextEdit *textEdit = new QTextEdit;<br /> splash->showMessage(QObject::tr("Loading modules..."),<br /> topRight,<br /> Qt::blue);<br /> QTest::qSleep(3000);<br /> textEdit->show();<br /> splash->finish(textEdit);<br /> delete splash;<br /> return app.exec();<br />} 

 

注意1:

啟動畫面圖片是通過setPixmap()來指定的,在這裡圖片是一個資源,因此,需要把圖片添加到資源檔(.qrc)中;否則,看不到啟動畫面。

 

注意2:

在例子程式中,使用了QTest::qSleep()函數,因此,需要包含標頭檔<QTest>,並在.pro檔案中,加入

        CONFIG += qtestlib

 

最終效果如下:

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.