首先,我将描述我的目标:我想在阻塞模式下通知用户有一些工作正在进行中。
我希望如果我在 QSplashScreen 中禁用点击隐藏,这将满足我的需要。在 C++ 中,它在 mousePressEvent 方法中处理:
void QSplashScreen::mousePressEvent(QMouseEvent *)
{
hide();
}
所以我希望只是覆盖这个方法会抑制隐藏,但我的代码不起作用:
from PyQt4 import QtGui, QtCore
import sys
import time
class MySplash(QtGui.QSplashScreen):
def __init__(self):
super(MySplash, self).__init__()
self.setPixmap(QtGui.QPixmap("betting.gif"))
def mousePressEvent(self, mouse_event):
print('mousePressEvent', mouse_event)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
splash = MySplash()
splash.show()
QtGui.qApp.processEvents()
print('Here I am')
splash.showMessage('Here I am')
time.sleep(2)
print('Do some work')
time.sleep(2)
splash.close()
我做错了什么?