Creating GUI Applications in Python using Qt I
log in to bookmark this presentaton
Novice / Tutorial
March 10th 9 a.m. – 12:20 p.m.
This tutorial is intended for Python programmers with no GUI programming experience with PyQt. The course will assist the programmer with the installation of the necessary tools and libraries to begin Qt development with Python. By the end of the course students have an understanding of the Qt library and tools and be able to create simple but useful GUIs in Python.
Below is an outline of the material to be presented during the class. The examples listed (unless otherwise noted) are developed while in class to show the process and progression of GUI development. - Installation Summary (10 min) - Reference to detailed instructions provided before the class began - Supported platforms - Windows - Linux - Mac - Introduction (25 min) - Motivations for choosing Qt - The licensing of Qt and PyQt - The alternatives to Qt - The PySide library - The developer tools provided by Nokia - Qt help system - GUI Designer - Internationalization support - Developing for non-Desktop platforms - Nokia-provided examples and demos - GUI Programming (10 min) - The event loop - Using GUI code generators vs. hand coding - Mixing application logic with GUI logic; good or bad? - Using the API (20 min) - Issues with interfacing to a C++ library - Reading C++ prototypes and translating them to Python calls - Getters and setters - What you need to know about type conversions - When not to use a Qt type - Navigating the documentation - Qt widgets summary and their respective classes - Importing from the Qt modules - Writing a simple GUI (15 min) - Example 1: Dialog with QLabel - Layout managers QHBoxLayout and QVBoxlayout - Modified example 1 with the QHBoxLayout layout - Example 2: Dialog with QLabel and QSpinbox - Break (20 min) - The Qt signals and slots (20 min) - Qt's signaling system - Modified example 2 with QSpinbox value updating QLabel text - When to use multiple layout managers - Example 3: Dialog with QLabel, QSpinbox, and non-functional QPushButton - The slots of QDialog - Modified example 3 with QPushButton closing the application - Modified example 3 with close button right justified - Platform-specific layouts abstracted by Qt - Modified example 3 with close button provided by QButtonBox - Customizing Qt widgets through inheritance (10 min) - Extending the default Qt classes for modified functionality - A detailed look at QSpinBox - Example 4: A simple hexadecimal adder with two QLineEdit, two HexSpinBox, and one "ok" QButtonBox widgets with a popup popup result using QMessageBox - The GUI Designer (20 min) - Capabilities of the Designer - Why use it? - Recreating Example 3 dialog with the Designer - Running pyuic - Examining the code produced by pyuic - Creating a simple Makefile to run pyuic - Example 5: Super simple calculator with 4 radio-button operations and two inputs. Full equation with result is displayed at the time of any UI changes. Close button stops the application. - Final Example (30 min) - Implement a dialog that asks the user to select a .bmp or .png file using the QFileDialog widget. Once selected, the application will alert the user to any errors prohibiting its processing the file. A preview of the file's image will be added to the dialog along with information about the file (type, size, image size). - The example will require subclassing of QDialog in order for the image to scale properly as the dialog is scaled. Additional concepts of size policy will also be incorporated. - Summary