The wiki is in the process of moving to Please make your edits there.

PySideSimplicissimus_Module_2_CloseButton | Qt Wiki | Qt Project

English French [] 日本語


This will not take you more than 5 minutes: the purpose of this program is to enable a click on the pushButton to close the execution of this program. As always when editing .ui files, we start in the Qt Designer. Read the getting to know Qt Designer document [] now if you are unfamiliar with Qt Designer. We call the program rather colourfully, quitter, so that our Designer created MainWindow with one button is saved as quitter.ui.

All current source code for “Close”, “About”, “Show Licence”, all versions of “Combined”, “Engineering Application” aka “truss” are stored in one repository tuts4pyside. For your convenience, please install a copy of the repository with the following command:

  1.   git  clone

If you do not have git, pllease install it first. To convert quitter.ui to a python readable format,, do the following
  1.  pyside-uic quitter.ui -o

The file naming is convenient as one needs to remember only one name: quitter. The rest of the name helps recognise the purpose of the file.

Note: If you don’t have setuptools installed, you will get an error when trying to execute pyside-uic

  1.      Traceback (most recent call last):
  2.      File "c:\Python26\Scripts\", line 5, in <module>
  3.        from pkg_resources import load_entry_point
  4.    ImportError: No module named pkg_resources

You can find setuptools here: []

The listing of the program follows:

  1. #!/usr/bin/env python
  2. # - provide a button to quit this "program"
  4. import sys
  7. from ui_quitter import Ui_MainWindow
  9. class MainWindow(QMainWindow, Ui_MainWindow):
  10.     def __init__(self, parent=None):
  11.         super(MainWindow, self).__init__(parent)
  12.         self.setupUi(self)
  14. if __name__ == '__main__':
  15.     app = QApplication(sys.argv)
  16.     frame = MainWindow()
  18.     app.exec_()

If you run the program, you will find that it can be closed either by the usual click on the [x], or click of the button. An image of the GUI can be seen if you click on the following link:

Now look closely at the code. Where is the code enabling the button to close the program? It surely is not in the listing…

The reason for its absence is that it has been created on the Qt Designer, which has a signal-slot editor. We used it surreptitiously to connect “signal” to MainWindow.close() “slot”. It is imbedded in the quitter.ui file and following the conversion, in the file. And from that file, we imported Ui_MainWindow class, which is one of the ancestors of our MainWindow class. We use Python’s multiple inheritance to facilitate use of methods in the module.

There are other ways to “skin the cat” and we could avoid dual inheritance, but why not use it when it is convenient? The super digs deeper into the ancestry and initialises the immediate ancestor of MainWindow and thus the whole tree of ancestry.

You will notice that the init method of the MainWindow specifies the ancestor as None. That is kind of indication to PySide that the MainWindow is indeed the Main Window of the program.

Return to PySideSimplicissimus