[PySide] QApplication.processEvents() is not working

Laurence Anthony antwebid at gmail.com
Sun Aug 12 09:30:25 CEST 2012


Can someone explain why the button in the following code does not
become disabled and greyed out on being pressed, whereas it works
perfectly in PyQt? (You can confirm this by commenting out the from
PySide import and adding the PyQt4 import).

It seems that QtGui.QApplication.processEvents() is not working
properly, but being a novice to PySide, I may just have the syntax
wrong.

from __future__ import print_function
#from PyQt4 import QtGui, QtCore
from PySide import QtGui, QtCore
import sys

class Example(QtGui.QWidget):

    def __init__(self):
        super(Example, self).__init__()
        self.initUI()

    def initUI(self):

        self.qbtn = QtGui.QPushButton('Press', self)
        self.qbtn.clicked.connect(self.button_disable)
        self.qbtn.resize(self.qbtn.sizeHint())
        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('Button Disable')
        self.show()

    def button_disable(self):
        self.qbtn.setEnabled(False)
        QtGui.QApplication.processEvents()

        for i in range(1, 100000000):
            pass
        print("finished")
        self.qbtn.setEnabled(True)


if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())


Thank you!



More information about the PySide mailing list