If you want to create GUI applications with Python it can be tricky to know
where to start. There are a lot of new concepts you need to understand to get
anything to work. But, like any coding problem, the first step is learning to
approach the problem in the right way. In this book I take you right from the
basic principles of GUI development to creating your own, fully functional,
desktop apps with PySide2.
The first edition of this book was released in 2016. Since then it has been
updated 4 times, adding and expanding chapters in response to reader
feedback. There are more PySide2 resources available now than when I
started, but there is still a shortage of in-depth, practical guides to building
complete apps. This book fills that gap!
The book is formatted as a series of chapters exploring different aspects of
PySide2 in turn. They are arranged to put the simpler chapters toward the
beginning, but if you have specific requirements for your project, don’t be
afraid to jump around! Each chapter will guide you through learning the
fundamental concepts before taking you through a series of coding
examples to gradually explore and learn how to apply the ideas yourself.
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
【One-Line Pitch】
A hands-on, project-driven guide to building desktop applications with Python and PySide2 (Qt5), perfect for developers who want to move from scripting to creating polished, functional GUI apps.
【Book Arc】
- **Opening (~0%–10%)**: Introduces the core concepts of GUI development—QApplication, QMainWindow, the event loop, and basic widgets—establishing the mental model needed to approach GUI programming correctly.
- **Early (~10%–24%)**: Covers layout management, signals and slots, toolbars, menus, dialogs, and multiple windows, then transitions to Qt Designer for visual UI creation and resource management.
- **Early (~24%–31%)**: Explores styling and customization—from QSS (Qt Style Sheets) for theming to the ModelView architecture, which separates data from presentation for scalable, maintainable apps.
- **Middle (~31%–45%)**: Builds practical applications, including a Todo app using ModelView and a database-driven app with QSqlTableModel and QSqlQueryModel, demonstrating real-world data integration.
- **Middle (~45%–52%)**: Delves into advanced signal handling, custom events, and routing patterns, plus a deep dive into bitwise flags for combining widget states and properties.
- **Late (~52%–end)**: Focuses on custom painting with QPainter, covering points, lines, and shapes, and likely wraps up with packaging and distribution considerations for shipping your app.
【Key Takeaways】
- **The event loop is the heart of GUI apps** (Opening): Understanding how QApplication.exec_() processes events is fundamental; it's the engine that makes signals, repaints, and user interactions work. This mental model prevents common beginner confusion.
- **Signals and slots decouple triggers from effects** (Early): A button press can chain multiple actions without those actions knowing what caused them. This decoupling is the key architectural principle for building maintainable GUI code.
- **Layouts beat absolute positioning** (Early): Using QHBoxLayout, QVBoxLayout, and nested layouts with margins and spacing creates responsive UIs that adapt to window resizing, unlike fixed coordinates.
- **Qt Designer accelerates UI creation** (Early): Designing .ui files visually and compiling them with pyside2-uic saves time, while the Qt Resource System (pyside2-rcc) bundles icons and assets for clean distribution.
- **ModelView separates data from presentation** (Early): Standard widgets like QListWidget mix data and display, causing sync headaches. ModelView (e.g., QListView with a custom model) isolates data, making updates and large datasets efficient.
- **QSS stylesheets give full visual control** (Early): From simple color changes to targeting specific widget sub-elements (like QSpinBox arrows), Qt Style Sheets let you theme your entire app consistently, including dark modes.
- **Database integration is straightforward** (Middle): QSqlTableModel and QSqlQueryModel connect to SQLite (or servers) with minimal code, and parameterized queries with bound values prevent SQL injection while enabling live search filters.
- **Bitwise flags enable compound states** (Middle): Understanding how Qt uses binary flags (e.g., Qt.AlignLeft | Qt.AlignBottom) lets you combine multiple properties into a single variable, a pattern used throughout Qt APIs.
【Reading Tips】
- **Skim the early widget examples** (~0–10%): The basic window and widget demos are repetitive; focus on the signals/slots section and the event loop explanation, which are the conceptual foundation.
- **Deep-read the ModelView chapter** (~31%): This is the most conceptually dense part; work through the Todo app code line-by-line to grasp how models, views, and layoutChanged signals interact.
- **Jump to Qt Designer if you prefer visual tools** (~21%): If you dislike hand-coding layouts, this section shows a faster workflow; you can always return to manual code later.
- **Practice the database chapter with your own data** (~41%): The Chinook database example is great, but swapping in your own SQLite file makes the concepts stick and prepares you for real projects.
- **Don't skip the bitwise flags section** (~52%): It seems theoretical, but understanding flags is essential for custom painting and advanced widget configuration later.
【Coverage Limits】
The excerpts cover roughly the first half of the book (through custom painting basics); later chapters on packaging, deployment, and advanced QPainter techniques are not included in this guide.
Excerpt 1
ize window, notice that the maximize control is disabled on Windows & Linux. On macOS you can maximize the app to fill the screen, but the central widget wil...
und: green; } QSpinBox::down-button { background: red; } Figure 129. Setting background to the QSpinBox up and down buttons. The arrows inside the up down...
option.rect(), with the width adjusted by the % completion. Finally, we write the job_id text over the top of this. Starting a job With everything in place, ...
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Loading comments...
Reply to Comment
Edit Comment