c – 模型 – 视图 – Qt中的控制器

我或多或少了解MPV的工作原理.
但我不知道什么课程:

> QAbstractItemModel
> QAbstractItemView
> QAbstractItemDelegate / QItemDelegate

可以为我做吗

如果这是相关的,我正在使用
QGraphicsScene / QGraphicsView具有用户可以与交互逻辑(游戏规则)封装在其他类中的一些元素(游戏板的可视化表示).

解决方法

AbstractItemModel QAbstractItemView QAbstractItemDelegate

来自“Mode/View framework”
这是您应用程序数据部分非常强大的框架,here是框架的演示.

化QAbstractItemModel

是MVC模型的基类.具有用于访问和更改数据的全局界面,并且可以监视Observable部分.

QAbstractItemView中

是MVC视图的基类.具有用于视图/选择部分的全局界面,并且它处理Observer部分.您不必担心观察者模式,框架为您而设.

QAbstractItemDelegate

是MVC的控制器的基类.
是绘画,编辑元素的策略模式,…

QGraphicsScene / QGraphicsView

来自“The Graphics View Framework”,独立于Model / View框架.
这也是图形部分非常强大的框架.

The Scene

QGraphicsScene provides the Graphics
View scene. The scene has the
following responsibilities:

Providing a fast interface for
managing a large number of items
Propagating events to each item
Managing item state,such as selection
and focus handling Providing
untransformed rendering functionality;
mainly for printing

The View

QGraphicsView provides the view
widget,which visualizes the contents
of a scene. You can attach several
views to the same scene,to provide
several viewports into the same data
set

如果您希望模型在QGraphicsView中可见,而不必根据QAbstractItemView编写自己的视图.
将QGraphicsView作为视图端口小部件QAbstractScrollArea :: setViewport(QWidget * widget)),然后可以

>添加QAbstractItemView :: rowsInserted,
>删除QAbstractItemView :: rowsAboutToBeRemoved
>并更改QAbstractItemView :: dataChanged

场景中的项目.不要忘记重新设置布局更改事件.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...