このコードはそれを行います。基本的に、ダミーのデリゲートアイテムを作成してから、同じ幅、高さ、x、yの値を持つ別のアイテムをその中に作成する必要があります。内側のアイテムの親をグリッドビューに設定します。これがうまくアニメーション化するように変更されたコードです。
import QtQuick 1.0
Rectangle {
id: mainRect
width: 300; height: 400
ListModel {
id: appModel
ListElement { modelcolor: "#FF0000"}
ListElement { modelcolor: "#00FF00"}
ListElement { modelcolor: "#0000FF"}
}
Component {
id: appDelegate
Item {
id: main
width: grid.cellWidth; height: grid.cellHeight
Rectangle {
id: item; parent: grid
x: main.x; y: main.y
width: main.width; height: main.height;
color: modelcolor
Behavior on x { NumberAnimation { duration: 400; easing.type: Easing.OutBack } }
Behavior on y { NumberAnimation { duration: 400; easing.type: Easing.OutBack } }
}
}
}
GridView {
id: grid
anchors.fill: parent
model: appModel
delegate: appDelegate
interactive: false
MouseArea {
anchors.fill: parent
onClicked: {
appModel.insert(1, { "modelcolor": "yellow" } )
}
}
}
}