QSplashScreen 类

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 * )

额外继承成员

详细描述

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

闪屏是应用程序启动时,通常显示的 Widget。闪屏常用于长启动时间的应用程序 (如:数据库或花时间建立连接的网络应用程序),为用户提供应用程序加载反馈。

闪屏出现在屏幕的中心。它可能是有用的,添加 Qt::WindowStaysOnTopHint 到 Splash 小部件的窗口标志,若希望使其保持在桌面所有其它窗口之上。

Some X11 window managers do not support the "stays on top" flag. A solution is to set up a timer that periodically calls raise () on the splash screen to simulate the "stays on top" effect.

The most common usage is to show a splash screen before the main widget is displayed on the screen. This is illustrated in the following code snippet in which a splash screen is displayed and some initialization tasks are performed before the application's main window is shown:

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 () 去接收鼠标点击。

It is sometimes useful to update the splash screen with messages, for example, announcing connections established or modules loaded as the application starts up:

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 () function. If you wish to do your own drawing you can get a pointer to the pixmap used in the splash screen with pixmap (). Alternatively, you can subclass QSplashScreen and reimplement 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 .

[virtual] 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 is displayed before calling close () on itself.

QString QSplashScreen:: message () const

Returns the message that is currently displayed on the splash screen.

该函数在 Qt 5.2 引入。

另请参阅 showMessage () 和 clearMessage ().

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

This signal is emitted when the message on the splash screen changes. message is the new message and is a null-string when the message has been removed.

另请参阅 showMessage () 和 clearMessage ().

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

重实现自 QWidget::mousePressEvent ().

const QPixmap QSplashScreen:: pixmap () const

Returns the pixmap that is used in the splash screen. The image does not have any of the text drawn by showMessage () calls.

另请参阅 setPixmap ().

void QSplashScreen:: repaint ()

This overrides QWidget::repaint (). It differs from the standard repaint function in that it also calls QApplication::processEvents () to ensure the updates are displayed, even when there is no event loop present.

void QSplashScreen:: setPixmap (const QPixmap & pixmap )

Sets the pixmap that will be used as the splash screen's image to pixmap .

另请参阅 pixmap ().

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

绘制 message text onto the splash screen with color color and aligns the text according to the flags in alignment . This function calls repaint () to make sure the splash screen is repainted immediately. As a result the message is kept up to date with what your application is doing (e.g. loading files).

另请参阅 Qt::Alignment , clearMessage (),和 message ().