[QtGui module]
该QSplashScreen小工具提供了可以在应用程序启动时显示启动画面。More…
继承QWidget。
Methods
__init__ (self, QPixmap pixmap = QPixmap(), Qt.WindowFlags flags = 0)
__init__ (self, QWidget parent, QPixmap pixmap = QPixmap(), Qt.WindowFlags flags = 0)
clearMessage (self)
drawContents (self, QPainter painter)
bool event (self, QEvent e)
finish (self, QWidget w)
mousePressEvent (self, QMouseEvent)
QPixmap pixmap (self)
repaint (self)
setPixmap (self, QPixmap pixmap)
showMessage (self, QString message, int alignment = Qt.AlignLeft, QColor color = Qt.black)
Qt Signals
void messageChanged (const QString&)
Detailed Description
该QSplashScreen小工具提供了可以在应用程序启动时显示启动画面。
启动画面是当一个应用程序被启动,通常是显示一个小部件。闪屏通常用于应用程序早就启动时间(如数据库或需要时间来建立连接的网络应用程序)向用户提供反馈,该应用程序加载。
在启动画面出现在屏幕中央。它可能是有用的添加Qt.WindowStaysOnTopHint在飞溅小部件的窗口标志,如果你想保留它上面的所有桌面上的其他窗口。
有些X11窗口管理器不支持标志“之上停留” 。一个解决办法是设置一个定期调用一个计时器raise_( )闪屏模拟“停留在顶部”的效果上。
最常见的用法是显示一个启动画面的主窗口部件被显示在屏幕上之前。说明了这一点,其中一个启动画面显示和一些初始化任务执行应用程序的主窗口显示之前,下面的代码片段:
int main(int argc, char *argv[])
{
[QApplication](docs_qapplication.html) app(argc, argv);
[QPixmap](docs_qpixmap.html) pixmap(":/splash.png");
QSplashScreen splash(pixmap);
splash.show();
app.processEvents();
...
[QMainWindow](docs_qmainwindow.html) window;
window.show();
splash.finish(&window);
return app.exec();
}
用户可以通过点击鼠标隐藏的启动画面。由于之前的事件循环已经开始运行启动画面通常显示,它以定期调用是必要的QApplication.processEvents()接收的鼠标点击。
它来更新消息中的闪屏有时是有用的,例如,宣布建立或加载的应用程序模块启动时连接:
[QPixmap](docs_qpixmap.html) 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()函数。如果你希望做自己的绘图,你可以得到一个指向在启动画面中使用的像素图与pixmap( ) 。或者,你可以继承QSplashScreen和重新实现drawContents( ) 。
Method Documentation
QSplashScreen.__init__ (self, QPixmap pixmap = QPixmap(), Qt.WindowFlags flags = 0)
构造一个初始屏幕,将显示pixmap。
应该没有必要设置窗口部件标记,f,也许除了Qt.WindowStaysOnTopHint。
QSplashScreen.__init__ (self, QWidget parent, QPixmap pixmap = QPixmap(), Qt.WindowFlags flags = 0)
该parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。
这是一个重载函数。
此功能允许您指定一个父为您的启动画面。典型的使用此构造函数是,如果你有多个屏幕,并希望有闪屏不同的屏幕比你小一上。在这种情况下,通过适当的桌面()中作为parent。
QSplashScreen.clearMessage (self)
这种方法也是一个Qt槽与C + +的签名void clearMessage()
。
删除所显示的初始屏幕上的消息
See also showMessage( ) 。
QSplashScreen.drawContents (self, QPainter painter)
用画家绘制的启动画面中的内容painter。默认实现绘制由传递消息showMessage( ) 。如果你想要做自己的绘图启动画面上重新实现这个函数。
bool QSplashScreen.event (self, QEvent e)
从重新实现QObject.event( ) 。
QSplashScreen.finish (self, QWidget w)
让启动画面等到小部件mainWin呼叫前显示close( )自身。
QSplashScreen.mousePressEvent (self, QMouseEvent)
从重新实现QWidget.mousePressEvent( ) 。
QPixmap QSplashScreen.pixmap (self)
返回用于在启动画面的像素图。图像没有任何被绘制文本showMessage( )调用。
See also setPixmap( ) 。
QSplashScreen.repaint (self)
这将复盖QWidget.repaint( ) 。其不同之处在于它也调用标准重绘函数QApplication.flush() ,以确保所显示的更新时,甚至当没有事件循环存在。
QSplashScreen.setPixmap (self, QPixmap pixmap)
设置将用作启动画面的图像的像素图pixmap。
See also pixmap( ) 。
QSplashScreen.showMessage (self, QString message, int alignment = Qt.AlignLeft, QColor color = Qt.black)
这种方法也是一个Qt槽与C + +的签名void showMessage(const QString&,int = Qt.AlignLeft,const QColor& = Qt.black)
。
绘制message文字上有颜色的闪屏color和对齐根据在标志的文本alignment。
为了确保在启动画面立即重绘,你可以调用QCoreApplication的processEvents()调用showMessage ()之后。通常你想这确保该消息被不断更新与你的应用程序在做(例如,加载文件) 。
See also Qt.Alignment和clearMessage( ) 。
Qt Signal Documentation
void messageChanged (const QString&)
这是该信号的默认超载。
这个信号被发射时,在启动画面变化的消息。message是新的消息,当该消息已被删除一个空字符串。
See also showMessage()和clearMessage( ) 。