PyQT6&Pyside6
<p>考虑用python来做desktop GUI</p>
ModelView
作者: n5321
需求:As you start to build more complex applications with PyQt6 you’ll likely come across issues keeping widgets in sync with your data.
ModelViews are a powerful alternative to the standard display widgets, which use a standardized model interface to interact with data sources — from simple data structures to external databases.
Table, list and tree widgets are components frequently used in GUIs.
The second approach is model/view programming, in which widgets do not maintain internal data containers. They access external data through a standardized interface and therefore avoid data duplication.
widget跟data的decouple!
Model/View is a technology used to separate data from views in widgets that handle data sets. 我使用GUIDE的方式,最烦的就是这个问题。
| Standard widgets use data that is part of the widget. |
|
| View classes operate on external data (the model) |
|
in Qt-speak the View and Controller are instead merged together creating a Model/ViewController architecture — called "Model View" for simplicity
you need to provide a wrapper to make your data conform to the QAbstractItemModel interface.


完了!又要耗时间了!
The .ui file was converted to a Python file as described previously using the command-line tool!
试用了qt designer,生成.ui文档,是matlab figure文档的平行竞品!同样的logic!这个看起来好像要灵魂一些!另外一点是他可以用纯粹的code来生成页面!有不一样的点!
ui file 通过cmd 生成py file!在generate idea的时候有价值!
优点
-
快速迭代界面
-
不需要每次修改
.ui文件都重新生成 Python 文件 -
修改完界面直接运行程序即可看到效果
-
-
减少生成文件
-
项目中不需要大量
*_ui.py文件 -
对小型或快速原型项目非常方便
-
-
动态选择界面
-
可以根据用户配置或条件选择不同的
.ui文件加载不同界面
-
2️⃣ 推荐的桌面应用开发流程(MV / MVC 风格)
-
设计 View(UI)
-
用 Qt Designer 设计
.ui文件 -
布局控件、设置大小、文本、图标等
-
可以生成 Python 文件或动态加载
-
-
定义 Model(数据层)
-
定义数据结构、业务逻辑
-
在 PyQt6 中,可以用
QAbstractListModel/QAbstractTableModel设计数据接口
-
-
实现 Controller / 逻辑
-
连接 View 与 Model
-
绑定信号槽,处理用户操作、更新数据、刷新界面
-
-
测试和迭代
-
运行程序,检查交互、布局、功能是否符合预期
-
调整 UI 或逻辑
-
We define our custom model by subclassing from a base implementation, allowing us to focus on the parts unique to our model.
集成default class!

