QSplashScreen 類

The QSplashScreen widget provides a splash screen that can be shown during application startup. 更多...

頭: #include <QSplashScreen>
qmake: QT += widgets
繼承: QWidget

公共函數

QSplashScreen (const QPixmap & pixmap = QPixmap(), Qt::WindowFlags f = Qt::WindowFlags())
QSplashScreen (QWidget * parent , const QPixmap & pixmap = QPixmap(), Qt::WindowFlags f = Qt::WindowFlags())
virtual ~QSplashScreen ()
void finish (QWidget * mainWin )
QString message () const
const QPixmap pixmap () const
void repaint ()
void setPixmap (const QPixmap & pixmap )

公共槽

void clearMessage ()
void showMessage (const QString & message , int alignment = Qt::AlignLeft, const QColor & color = Qt::black)

信號

void messageChanged (const QString & message )

保護函數

virtual void drawContents (QPainter * painter )

重實現保護函數

virtual bool event (QEvent * e )
virtual void mousePressEvent ( QMouseEvent * )

額外繼承成員

詳細描述

The QSplashScreen widget provides a splash screen that can be shown during application startup.

閃屏是應用程序啓動時,通常顯示的 Widget。閃屏常用於長啓動時間的應用程序 (如:數據庫或花時間建立連接的網絡應用程序),為用戶提供應用程序加載反饋。

閃屏齣現在屏幕的中心。它可能是有用的,添加 Qt::WindowStaysOnTopHint 到 Splash 小部件的窗口標誌,若希望使其保持在桌麵所有其它窗口之上。

一些 X11 窗口管理器不支持 "停留在頂部" 標誌。解決方案是設置計時器周期性調用 raise () 在閃屏以模擬 "停留在頂部" 效果。

最常見用法是展示閃屏,在屏幕中顯示主 Widget 前。以下代碼片段將闡明這,顯示閃屏並履行一些初始化任務,在展示應用程序主窗口前:

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QPixmap pixmap(":/splash.png");
    QSplashScreen splash(pixmap);
    splash.show();
    app.processEvents();
    ...
    QMainWindow window;
    window.show();
    splash.finish(&window);
    return app.exec();
}
					

The user can hide the splash screen by clicking on it with the mouse. Since the splash screen is typically displayed before the event loop has started running, it is necessary to periodically call QApplication::processEvents () 以接收鼠標點擊。

有時很有用采用消息更新閃屏,例如,在應用程序啓動時宣布建立連接 (或加載模塊):

QPixmap pixmap(":/splash.png");
QSplashScreen *splash = new QSplashScreen(pixmap);
splash->show();
... // Loading some items
splash->showMessage("Loaded modules");
qApp->processEvents();
... // Establishing connections
splash->showMessage("Established connections");
qApp->processEvents();
					

QSplashScreen supports this with the showMessage () 函數。若希望自己繪製,可以獲取用於閃屏的像素圖指針采用 pixmap (). Alternatively, you can subclass QSplashScreen 並重實現 drawContents ().

成員函數文檔編製

QSplashScreen:: QSplashScreen (const QPixmap & pixmap = QPixmap(), Qt::WindowFlags f = Qt::WindowFlags())

構造閃屏顯示 pixmap .

應該不需要設置 Widget 標誌, f ,或許除瞭 Qt::WindowStaysOnTopHint .

QSplashScreen:: QSplashScreen ( QWidget * parent , const QPixmap & pixmap = QPixmap(), Qt::WindowFlags f = Qt::WindowFlags())

這是重載函數。

This function allows you to specify a parent for your splashscreen. The typical use for this constructor is if you have a multiple screens and prefer to have the splash screen on a different screen than your primary one. In that case pass the proper desktop() as the parent .

[虛擬] QSplashScreen:: ~QSplashScreen ()

析構函數。

[slot] void QSplashScreen:: clearMessage ()

移除在閃屏上顯示的消息

另請參閱 showMessage ().

[virtual protected] void QSplashScreen:: drawContents ( QPainter * painter )

繪製閃屏的內容,使用描繪器 painter 。默認實現繪製傳遞的消息,通過 showMessage ()。重實現此函數,若想在閃屏做自己的繪圖。

[virtual protected] bool QSplashScreen:: event ( QEvent * e )

重實現自 QObject::event ().

void QSplashScreen:: finish ( QWidget * mainWin )

使閃屏等待,直到小部件 mainWin 顯示先於調用 close () 在自身。

QString QSplashScreen:: message () const

返迴閃屏中目前顯示的消息。

該函數在 Qt 5.2 引入。

另請參閱 showMessage () 和 clearMessage ().

[signal] void QSplashScreen:: messageChanged (const QString & message )

此信號發射,當閃屏中的消息改變時。 message 為新消息,和為 null 字符串當消息已移除時。

另請參閱 showMessage () 和 clearMessage ().

[virtual protected] void QSplashScreen:: mousePressEvent ( QMouseEvent * )

重實現自 QWidget::mousePressEvent ().

const QPixmap QSplashScreen:: pixmap () const

返迴閃屏中使用的像素圖。圖像不擁有任何繪製文本通過 showMessage () 調用。

另請參閱 setPixmap ().

void QSplashScreen:: repaint ()

這覆寫 QWidget::repaint ()。它不同於標準重新描繪函數,因為它還調用 QApplication::processEvents () 以確保顯示更新,即使不存在事件循環。

void QSplashScreen:: setPixmap (const QPixmap & pixmap )

把用作閃屏圖像的像素圖設為 pixmap .

另請參閱 pixmap ().

[slot] void QSplashScreen:: showMessage (const QString & message , int alignment = Qt::AlignLeft, const QColor & color = Qt::black)

繪製 message 文本在閃屏中采用顔色 color 並對齊文本根據標誌 alignment 。此函數調用 repaint () 以確保立即重新描繪閃屏。因此,消息隨應用程序在做的保持更新 (如:加載文件)。

另請參閱 Qt::Alignment , clearMessage (),和 message ().