也许您的模型或委托,或布局(项目重叠......)有问题,因为在这里,这很好用:
import QtQuick 2.0;
Rectangle {
width: 400;
height: 300;
Timer {
running: true;
repeat: true;
interval: 1000;
onTriggered: { modelTest.append ({ "bg" : Qt.hsla (Math.random (), 0.85, 0.45, 1.0).toString () }); }
}
Flow {
anchors.fill: parent;
Repeater {
model: ListModel {
id: modelTest;
}
delegate: Rectangle {
id: rect;
color: model.bg;
width: 50;
height: width;
scale: 0.0;
PropertyAnimation {
target: rect;
property: "scale";
from: 0.0;
to: 1.0;
duration: 450;
running: true;
loops: 1;
}
}
}
}
}
请记住,只有 ListModel 和 QAbstractListModel 能够在不重置整个委托的情况下动态添加新项目,另一个(变体列表、JS 数组、数字)将导致在每次模型修改时重新实例化所有委托...