PyQt and MVC-pattern

前端 未结 3 1307
孤独总比滥情好
孤独总比滥情好 2021-01-29 22:21

I am trying to design an MVC-pattern with PyQt. I want to split all programs into 3 parts:

  1. classes abstracted from all Qt classes (model)
  2. classes providin
3条回答
  •  一生所求
    2021-01-29 22:43

    Yes, PyQt uses Model/View concept (officially without the "Controller" part), but may be you have a somewhat distorted picture what does it mean in PyQt.

    There are two parts:

    1. Models, subclassed from appropriate PyQt base abstract model classes (QAbstractItemModel, QAbstractTableModel, QAbstractListModel, etc.). These models can talk to your data sources directly (files, databases), or proxy your own PyQt-agnostic models which were written before.
    2. Views, which are implemented in Qt library, and often do not require any modifications (examples: QTreeView, QTableView and others). Even some simpler controls, like QComboBox can act as a view for a PyQt model.

    All other parts of you application, which react to signals, etc. may be considered as "Controller".

    PyQt also provides a set of predefined "universal" models which can be subclassed or used directly if you need only simple functionality from the model, like QStringListModel, QStandardItemModel, etc. And there are also models which can talk to databases directly, like QSqlTableModel.

提交回复
热议问题