PyQt5 Development Practice (Part 1: Preparation)
Preface Over the past year I've developed quite a few small PyQt projects. Since I hadn't used Qt with C++ before, you could say I started from scratch, learning as I went. In the process I once again felt how lacking the domestic tech community is... There's not exactly little material on PyQt in China, but not a lot either—it's mainly scattered, and there aren't really any decent systematic learning resources... So for this PyQt, it all came down to reading the docs and overseas communities, plus the most important thing: figuring it out myself... Setting Up the Development Environment The development environment setup in this article is partly learned from a book, and partly from practice tot
目录8 个章节
Preface
Over the past year I've developed quite a few small PyQt projects. Since I hadn't used Qt with C++ before, you could say I started from scratch, learning as I went. In the process I once again felt how lacking the domestic tech community is... There's not exactly little material on PyQt in China, but not a lot either—it's mainly scattered, and there aren't really any decent systematic learning resources... So for this PyQt, it all came down to reading the docs and overseas communities, plus the most important thing: figuring it out myself...
Setting Up the Development Environment
The development environment setup in this article is partly learned from a book and partly summarized from practice. In short, given that there currently isn't a particularly good PyQt integrated development tool, this achieves a reasonably efficient development workflow for the time being.
The PyQt development approach I currently use follows the traditional MVC architecture, separating UI layout from logic implementation~
Specifically:
- Design the UI with QtDesigner, save it as a
*.uifile, then usepyuic5from the PyQt tools to convert the ui file into a py file—this is the view - Create corresponding py files in the controller package to implement the corresponding UI logic
Project structure for reference:

Using QtDesigner
This QtDesigner is pretty crude. Never mind comparing it to VS—even compared to the Swing UI designer in Android Studio or IDEA, it's the little brother. It's maybe about 60–70% of the level of VB 6.0 from 1998...
Still, it's better than nothing. At least you can design simple UIs, and that's enough.
Having written a lot of Flutter and Android apps, I'm very used to various linear layouts. Qt isn't bad at layout either—there are Hlayout and Vlayout you can use, and they're convenient in QtDesigner as well: create a Main window, drop a few widgets on it, right-click to set the layout, then you can freely use HLayout, VLayout, GridLayout and other components for layout, as shown:

Installing PyQt Tools
To use the tools mentioned above such as QtDesigner and pyuic5, you need to install them first.
pip install pyqt5
pip install pyqt5-tools
After installation, you can find the PyQt5 and pyqt5-tools folders under Lib/site-packages in the Python installation directory. The tools we need, such as QtDesigner and pyuic5, are in the pyqt5-tools folder.
Configuring External Tools in PyCharm
To make PyQt development more convenient in PyCharm, you also need to configure a few external tools. After configuring them you can do some quick operations: for example, right-click a ui file to open it directly with QtDesigner, or convert a UI file to a py file, as shown:

The specific configuration method is as follows:
First, File->Settings, open PyCharm's settings, and go to the External Tools screen, as shown

Here click the plus button to open the add page. We'll add QtDesigner first, as shown

Next add the pyuic5 tool. This tool's command argument format is as follows:
{pyuic5_path} -o {target_path} {file_path}
So the configuration is like this:

I'll copy the arguments part again:
-o $FileDir$/$FileNameWithoutExtension$.py $FilePath$
Recommending a Small Open Source Project
This is a simple video merging tool I wrote before. Below is a brief project introduction
I wanted to merge videos but couldn't find a decent tool—many of them charge money. I thought, "This crappy feature and they still want to charge?", so I decided to make one myself. At first I made one with Python; it worked pretty well and perfectly completed my video merging tasks, but it had no GUI, so I couldn't share it with friends to use. Then I wrote a GUI with Qt and put it on top, and that's how this project came about

Link: https://github.com/Deali-Axy/VideoMerge
Recommending a Book
Although systematic learning materials in China are scarce, I did manage to find this one

I forget where I found the PDF. It has no table of contents, so looking things up is a pain. I spent time going through the whole book and manually marked up a table of contents, as shown

I'd say I more or less understand the contents of the whole book. The earlier parts on setting up a PyQt development environment and such are still somewhat helpful; later on, the introductions to various widgets aren't that detailed. Some useful things aren't even covered in the book, so you still have to rely on Google. So, this book can only be described as the tallest among dwarfs—barely satisfactory~
Welcome to Discuss
Programming Lab focuses on exploring popular new internet technologies and team agile development practices. Reply linux, flutter, c#, netcore, android, kotlin, java, python, etc. in the backend of the WeChat official account "Programming Lab" to get related technical articles and materials. You can also leave a message in the official account backend if you have any questions~

- Blog Garden: https://www.cnblogs.com/deali/
- Coding livestream: https://live.bilibili.com/11883038
- Zhihu: https://www.zhihu.com/people/dealiaxy
_EOF_
PyQt5 Development Practice (Part 1: Preparation)
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
数据分析必备技能!3分钟教会你如何在PyQt中画好看的图表
先看看我们要实现的效果: 这是一个基于机器学习的数据分析结果展示,可以看到元素包括了坐标轴标注,两条折线和图例。 为了实现在PyQt中画图,我们用到了pyqtgraph这个绘图库,它是完全python实现的,与PyQt程序可以完美融合,并且具备很多优势: 拥有丰富的图形种类; 能够快速地实时更新绘图数据; 能够进行交互式的操作; 多种标记功能; 接下来进入正题,开始使用pyqtgraph来实现我们
2021-12-18 · PyQt · 约 1 分钟
初秋——银烛秋光冷画屏
朝来入庭树,孤客最先闻。 对刘禹锡的这几句诗,我大概算是有所感触了。 第二个不在家过的中秋节将至,即使天气依然很热,但是渐渐提早的落日以及断断续续的雨水,无不预示秋的到来。 图:学校的黄昏 当我读到刘禹锡这首《秋风引》时,就不自觉的把它套入这个意境中。 秋风悄无声息潜入庭院,其实在外的旅人最先听到秋的声音。 作为一个喜欢写散文的人,春、夏、秋、冬,四个季节,几乎每年我都会写,每次写时的心境却又是大
2022-11-07 · 2017 · 约 1 分钟
Asp-Net-Core学习笔记:身份认证入门
前言 过年前我又来更新了~ 我就说了最近不是在偷懒吧,其实这段时间还是有积累一些东西的,不过还没去整理…… 所以只能发以前没写完的一些笔记出来 就当做是温习一下啦 PS:之前说的红包封面我还没搞,得抓紧时间了 最近在准备搞一个我之前做的开源项目代码合集来做一期分享 两种常见的认证方式 先来看看两种常见的认证方式:基于token的认证和传统的session认证的区别。 session认证 我们知道,
2022-02-16 · Asp-Net-Core学习笔记 · 约 1 分钟
基于.NetCore开发博客项目 StarBlog - (30) 实现评论系统
开发者终于更新评论系统,代码量庞大只贴关键逻辑,GitHub自便。前端ElementUI与Bootstrap风格冲突,却称和谐?评论需邮箱验证码,审核流程繁琐,自动不通过还得人工。
2025-04-27 · StarBlog博客开发笔记 · 约 1 分钟
讨论
共 0 条加载评论中…