[PySide] QApplication.processEvents() is not working

Aaron Richiger a.richi at bluewin.ch
Sun Aug 12 11:48:59 CEST 2012


Hello Laurence!

Quite a bomb you that you sent us here... I had to power off my machine 
after 10 frozen minutes:-)! So for others who want to test your code, it 
might be a good idea to start with a smaller upper bound for the loop 
unless you are on a high performance machine:-)

I get exactly the same behaviour with PyQt4 on my Ubuntu 12.04. So it 
seems to be a Qt and not a PySide thing. There is a solution (don't ask 
me for the reason, I just know it works for me...):
Call processEvents() multiple times. Here 2 times is enough for me, but 
I observed in other projects, that sometimes it needs even more calls 
until all events are processed as expected. With this workaround, it 
also works with PyQt4.

I hope this helps! Cheers!
Aaron




Am 12.08.2012 09:30, schrieb Laurence Anthony:
> 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!
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside




More information about the PySide mailing list