[PySide] QApplication::processEvents( ), re: Why doesn't this example work?
peter_karasev at keysight.com
peter_karasev at keysight.com
Fri Oct 24 20:48:48 CEST 2014
Related question to this:
in C++ you can do this to make events start running before QApplication.exec() is called:
// if you do this in a while-loop, you can interact with widgets ...
Is it not possible to do this from PySide? I tried to make a C++ wrapper object
but it seemed like the PySide objects weren't getting updated, although C++ QT widgets would appear and allow you to interact before
От: pyside-bounces+peter_karasev=keysight.com at qt-project.org [pyside-bounces+peter_karasev=keysight.com at qt-project.org] от имени Jim Byrnes [jf_byrnes at comcast.net]
Отправлено: 24 октября 2014 г. 11:29
Кому: pyside at qt-project.org
Тема: Re: [PySide] Why doesn't this example work?
On 10/22/2014 11:26 PM, Sean Fisk wrote:
> Hi Jim,
> With all due respect to the author of the book, I don’t think this is a
> very good example. The most important thing to realize is that nothing
> really happens before the event loop is started. The line:
> is what starts the event loop. Without the event loop running, windows
> won’t appear, user input cannot be handled, and basically nothing
> QtGui-related will work. *Even if* windows show up before the event loop is
> started, they won’t be able to respond to user interaction (as far as I
> I would personally achieve the desired behavior like so:
> #!/usr/bin/env python
> import sys
> from PySide import QtCore, QtGui
> class SampleWindow(QtGui.QWidget):
> def __init__(self, parent=None):
> super(SampleWindow, self).__init__(parent)
> self.setWindowTitle('Sample Window')
> self.setGeometry(300, 300, 200, 150)
> def do_resize(self):
> self.resize(300, 300)
> self.setWindowTitle('Sample Window Resized')
> def main(argv):
> app = QtGui.QApplication(argv)
> # Create and show the window.
> window = SampleWindow()
> # PySide windows don't auto-raise on Mac OS X.
> # Set up a timer to fire 3 seconds *after the event loop starts*.
> QtCore.QTimer.singleShot(3000, window.do_resize)
> # Start the event loop. Nothing Qt-related happens until this call.
> return app.exec_()
> if __name__ == '__main__':
> raise SystemExit(main(sys.argv))
> The key take-away is that nothing QtGui-related *actually* happens before
> the event loop is started, and everything is done by the time that it exits.
> Hope this helps. Feel free to let me know if anything doesn’t make sense.
Thanks for the code and the explanation. It works and I can follow it
and understand what is happening.
> Sean Fisk
> On Wed, Oct 22, 2014 at 8:17 PM, Jim Byrnes <jf_byrnes at comcast.net> wrote:
>> In looking at the lists archives, I see that most of the participants
>> seem to be experienced developers. As a novice programmer I hope I am
>> not intruding by asking some basic questions.
>> I am working my way through examples in a PySide book I bought.
>> According to the author the example should display a 200 x 150 window,
>> pause 3 seconds and then display a 300 x 300 window. On my system
>> (Ubuntu 12.04) there is a approx 3 second delay after starting the
>> program and then I see the 300 x 300 window. I never see the first window.
>> Could someone explain to me why it does not act as described?
>> # Import required modules
>> import sys
>> import time
>> from PySide.QtGui import QApplication, QWidget
>> class SampleWindow(QWidget):
>> """ Our main window class
>> # Constructor function
>> def __init__(self):
>> self.setWindowTitle("Sample Window")
>> self.setGeometry(300, 300, 200, 150)
>> if __name__ == '__main__':
>> # Exception Handling
>> myApp = QApplication(sys.argv)
>> myWindow = SampleWindow()
>> myWindow.resize(300, 300)
>> myWindow.setWindowTitle("Sample Window Resized")
>> except NameError:
>> print("Name Error:", sys.exc_info())
>> except SystemExit:
>> print("Closing Window...")
>> except Exception:
>> print (sys.exc_info())
>> Thanks, Jim
>> PySide mailing list
>> PySide at qt-project.org
> PySide mailing list
> PySide at qt-project.org
PySide mailing list
PySide at qt-project.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PySide