QSplashScreen Class Reference

[ QtGui module]

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

继承 QWidget .

方法

Qt Signals


详细描述

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

A splash screen is a widget that is usually displayed when an application is being started. Splash screens are often used for applications that have long start up times (e.g. database or networking applications that take time to establish connections) to provide the user with feedback that the application is loading.

The splash screen appears in the center of the screen. It may be useful to add the Qt.WindowStaysOnTopHint 到 splash widget's window flags if you want to keep it above all the other windows on the desktop.

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 () to receive the mouse clicks.

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 支持这,采用 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.__init__ ( self , QPixmap   pixmap  = QPixmap(), Qt.WindowFlags   flags  = 0)

构造闪屏显示 pixmap .

应该不需要设置 Widget 标志, f , except perhaps Qt.WindowStaysOnTopHint .

QSplashScreen.__init__ ( self , QWidget   parent , QPixmap   pixmap  = QPixmap(), Qt.WindowFlags   flags  = 0)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

这是重载函数。

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.clearMessage ( self )

This method is also a Qt slot with the C++ signature void clearMessage() .

移除在闪屏上显示的消息

另请参阅 showMessage ().

QSplashScreen.drawContents ( self , QPainter   painter )

绘制闪屏的内容,使用描绘器 painter . The default implementation draws the message passed by showMessage (). Reimplement this function if you want to do your own drawing on the splash screen.

bool QSplashScreen.event ( self , QEvent   e )

重实现自 QObject.event ().

QSplashScreen.finish ( self , QWidget   w )

使闪屏等待,直到小部件 mainWin is displayed before calling close () on itself.

QSplashScreen.mousePressEvent ( self , QMouseEvent )

重实现自 QWidget.mousePressEvent ().

QPixmap QSplashScreen.pixmap ( self )

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

另请参阅 setPixmap ().

QSplashScreen.repaint ( self )

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

QSplashScreen.setPixmap ( self , QPixmap   pixmap )

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

另请参阅 pixmap ().

QSplashScreen.showMessage ( self , QString  message , int  alignment  = Qt.AlignLeft, QColor   color  = Qt.black)

This method is also a Qt slot with the C++ signature void showMessage(const QString&,int = Qt.AlignLeft,const QColor& = Qt.black) .

Draws the message text onto the splash screen with color color and aligns the text according to the flags in alignment .

To make sure the splash screen is repainted immediately, you can call QCoreApplication 's processEvents() after the call to showMessage(). You usually want this to make sure that the message is kept up to date with what your application is doing (e.g., loading files).

另请参阅 Qt.Alignment and clearMessage ().


Qt Signal Documentation

void messageChanged (const QString&)

This is the default overload of this signal.

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

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