This is an introductory PyQt5 tutorial with the goal of getting you started with the toolkit so that you can create functional UIs in Python. While I can’t hope to cover all of Qt (it’s a huge library) hopefully I can give you enough of an introduction to be able to take the API docs and create the UI you imagine. The tutorial code was written on a Windows machine with Python 3.6.1 and PyQt5. You’ll need to be a competent coder with intermediate Python skills to follow along but there is nothing particularly difficult.
Over the course of the tutorial, we’re going to write a code editor with a heap of nice features like a tabbed interface and project navigation which is built in a progressive manner. Later on, I’ll start to add ‘featurette’ articles to add extra features that don’t necessarily progress the tutorial but are nice little extras.
You can install PyQt5 with pip. On Windows –
pip3 install pyqt5
On Linux –
sudo pip3 install pyqt5
PyQt5 is organised into a number of modules, many of which are quite specific and not all that commonly used. There are however a couple of modules you’ll use in pretty much every UI project –
PyQt5.QtCorecontains core Qt functionality including data types like date & time, threads & processes and the
Qtobject which gives you access to enumerations for configuring various widgets and Qt objects.
PyQt5.QtGuicontains UI related objects that are not widgets – stuff like icons, images and UI events
PyQt5.QtWidgetsare the actual UI elements like layouts, and widgets
Qt5 Class Reference
The Qt5 class reference can be found here https://doc.qt.io/qt-5.10/classes.html – it’s for C++ but the API is almost exactly with the notable exception of data types that have a direct Python equivalent – we’ll cover these as we come across them.
Table of Contents
- Scaffolding – basic PyQt5 project setup / resources
- Widgets – introduction to widgets in Qt – QPlainTextEdit / QTabWidget / QMainWindow
- Toolbars, menus and actions
- MVC 1 – TreeView / FileSystemModel
- MVC 2 – Custom TreeView model