2

まず最初に、私の目標を説明します。ブロッキング モードのユーザーに、進行中の作業があることを通知したいと思います。

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

私が間違っていることは何ですか?

4

3 に答える 3

0

私の最初の質問への答えは簡単です:mousePressEvent保護されていると宣言されています-それがそれをオーバーライドすることができない理由です!

于 2013-03-07T09:13:19.313 に答える
0

mousePressEvent メソッドのオーバーライドが機能しない理由はまだわかりません (私はまだ興味があります) が、別の方法で問題を解決しました:

class BusyDialog(QtGui.QWidget):
    def __init__(self, parent = None):
        super(BusyDialog, self).__init__(parent)
        self.show()


class MainWindow(QtGui.QMainWindow):
    def __init__(self, parent = None):
        super(MainWindow, self).__init__(parent)
        self.button = QtGui.QPushButton('Click me', self)
        self.button.clicked.connect(self.button_clicked)

    def button_clicked(self):
        print('clicked')
        dialog = BusyDialog()
        QtGui.qApp.processEvents()
        time.sleep(2)
        print('Here I am')
        time.sleep(2)
        print('Do some work')
        time.sleep(2)
        dialog.close()


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    main = MainWindow()
    main.show()
    sys.exit(app.exec_())
于 2013-03-06T14:39:06.927 に答える