Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is there no reference between the app and the widget?

This is a follow up to why will the application show after sys.exit command?

I'm following this tutorial:

http://zetcode.com/tutorials/pyqt4/firstprograms/

I modified the code slightly to test things

import sys
from PyQt4 import QtGui


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    w = QtGui.QWidget()
    w.resize(250,150)
    w.move(300,300)
    w.setWindowTitle("Title")
    w.show()
    sys.exit(app.exec_())

I'm confused as to why there isn't a reference of app and w i'd expect some kind of indication that w is a child or something of app.

I'm running it in Spyder and an IPython interpreter.

like image 855
evan54 Avatar asked Dec 19 '25 20:12

evan54


1 Answers

For any GUI application using Qt, there is precisely one QApplication object, no matter whether the application has 0, 1, 2 or more windows at any given time. All windows are automatically managed by the Application.

You do have to initialize it and to get a hold of it to exec it though.

You must create the Application before any other GUI objects (because they are managed by it).

Detailed Description of the QApplication object

like image 116
Pavel Anossov Avatar answered Dec 21 '25 10:12

Pavel Anossov