Skip to content

Crash Course: Qt

Jared Ketterer edited this page Jul 25, 2020 · 1 revision

Basic Qt App

At it's core, a Qt app is this:

import sys
from PyQt5 import QtWidgets

app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QWidget()
window.show()
sys.exit(app.exec_())

The core app: QtWidgets.QApplication takes arguments from the terminal via sys.argv
The main window: QtWidgets.QWidget is created and shown with the .show() method
Finally, the application returns an exit code to the terminal with sys.exit(app.exec_())

QtWidgets and Subclasses

Qt has many modules, all with the naming convention of QtModule
Examples include: QtCore, QtWidgets & QtScript
If you find a handy C++ class in the Qt Documentation, you need to check the qmake field at the top of it's page
This will tell you the appropriate python module name to import: qmake: QT += widgets == QtWidgets

QtPyHammer subclasses a number of Qt C++ Classes to create widgets
The ui.viewport class is a subclass of QtWidgets.QOpenGLWidget
One of the most important differences between it's parent C++ class and the QPH class is the addition of a timer to redraw the viewport every 15ms

Clone this wiki locally