gpt4 book ai didi

c++ - Qt 中的模型 - View - Controller

转载 作者:IT老高 更新时间:2023-10-28 23:17:41 25 4
gpt4 key购买 nike

我或多或少了解 MPV 的工作原理。但我不知道什么类:

  • QAbstractItemModel
  • QAbstractItemView
  • QAbstractItemDelegate/QItemDelegate

可以帮我吗?

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

最佳答案

AbstractItemModel QAbstractItemView QAbstractItemDelegate

来自"Mode/View framework"
这是一个非常强大的应用程序数据部分的框架,here是框架的介绍。

QAbstractItemModel

MVC 模型 的基类。具有用于访问和更改数据的全局接口(interface),并负责 Observable 部分。

QAbstractItemView

MVC View 的基类。具有 View /选择部分的全局接口(interface),它负责观察者部分。您不必担心观察者模式,框架会为您完成。

QAbstractItemDelegate

MVC 的 Controller 的基类。
是用于绘画、编辑元素的策略模式,...


QGraphicsScene/QGraphicsView

来自"The Graphics View Framework"并且独立于模型/ 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 编写自己的 View 。
取一个 QGraphicsView 作为视口(viewport)小部件 QAbstractScrollArea::setViewport(QWidget * widget)) 然后就可以了

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

场景中的项目。不要忘记处理重置布局更改事件。

关于c++ - Qt 中的模型 - View - Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1004701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com