Other PyQt Goodies

Using Qt Designer

Qt Designer is a GPL'ed GUI design editor provided by Trolltech as part of Qt. It generates an XML description of a GUI design. Qt includes uic which generates C++ code from that XML.

PyQt includes pyuic which generates Python code from the same XML. The Python code is self contained and can be executed immediately.

Thanks to Christian Bird, pyuic will extract Python code entered using Qt Designer to implement slots. In Qt Designer, when you need to edit a slot and the source editor appears, enter Python code between the curly braces. Don't worry about the correct starting indent level, each line is prepended with a correct indentation.

Make sure that the ui.h file is in the same directory as the .ui file when using pyuic. The .ui file implies the name of the .ui.h file so there is no need to specify it on the command line.

Here's an example of a simple slot.

void DebMainWindowFrm::browsePushButtonClicked()
{
if self.debugging:
    QMessageBox.critical(self, "Event", "browse pushbutton was clicked!")
}

Here is the resulting code when pyuic is run.

class DebMainWindowFrm(QMainWindow):
    ...stuff...
    def browsePushButtonClicked(self):
        if self.debugging:
            QMessageBox.critical(self, "Event", "browse pushbutton was clicked!")

Note that indenting is as normal and that self and all other parameters passed to the slot are available.

If you use this, you will need to turn off all of the fancy options for the C++ editor in Designer as it tries to force C++ syntax and that's naturally annoying when trying to code in Python.

Using eric the Debugger

eric is a graphical debugger, written using PyQt, for debugging PyQt programs (or any Python program that doesn't use another GUI toolkit). Using eric you can single step through programs, set breakpoints (even while the program is running), and inspect and modify Python variables (again, while the program is running).

eric is maintained by Detlev Offenbach.