部分更新转发器 QML

Partial update repeater QML

我在 QML/C++ 项目中遇到了一个小问题。我正在使用中继器在矩形内绘制点,这些点来自模型。这是我的代码:

main.qml

Rectangle { 
      id: rect
      height:500
      width:500
      Repeater {
          id: pointsRepeater
          model: qListPoints
          Point {
          }
      }
}

qListPoints 来自我的 C++,我在其中写道: Q_PROPERTY( QVariant qListPoints READ getListPoints NOTIFY listPointsChanged)

所以基本上当我添加或更新列表点时,我会发出 listPointsChanged() 并且我的 main.qml 从列表中重绘新的或更新的点。我的问题是当我将点添加到我的列表并发出 listPointsChanged() 所有点都被重新绘制时,这就像一个缓慢的频闪效果。我只想重绘新点。可能吗 ?

提前致谢。

我认为,如果您使用从 QAbstractListModel, for example, then only the points that you add/change/remove will be redrawn. The problem that you're seeing is likely the same as the one mentioned here 派生的适当模型:

Note: There is no way for the view to know that the contents of a QList has changed. If the QList changes, it is necessary to reset the model by calling QQmlContext::setContextProperty() again.

视图只知道 属性 发生了变化,但它不知道该模型中特定项目的任何信息,因此它只是重新绘制所有内容。

Using C++ Models with Qt Quick Views 有更多关于此的信息。