我在 QML/C++ 项目中遇到了一个小问题。我正在使用中继器在矩形内绘制点,这些点来自模型。这是我的代码:
main.qml
Rectangle {
id: rect
height:500
width:500
Repeater {
id: pointsRepeater
model: qListPoints
Point {
}
}
}
qListPoints 来 self 写的 C++:
Q_PROPERTY(QVariant qListPoints READ getListPoints NOTIFY listPointsChanged)
所以基本上,当我添加或更新列表点时,我会发出 listPointsChanged() ,并且我的 main.qml 从列表中重新绘制新的或更新的点。我的问题是,当我将点添加到列表中并发出 listPointsChanged() 时,所有点都会重新绘制,这就像缓慢的频闪效果。我只想要新点或者重画。是否可以 ?
提前谢谢您。
最佳答案
我认为如果您使用源自 QAbstractListModel 的正确模型例如,只有您添加/更改/删除的点才会被重绘。您看到的问题可能与提到的问题相同 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.
View 只知道属性已更改,但它不知道该模型中特定项目的任何信息,因此它只是重绘所有内容。
关于qt - 部分更新中继器QML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29969766/