Javascript 如何使用QML为GridView中的每个项目制作淡入动画
每次gridview的模型更改时,我都会尝试制作淡入动画。 我试图利用链接中提到的示例: 但我正试着在ADD的附加信号上做这件事 是否有可能或是否有我可以使用的解决方法 下面是我的代码Javascript 如何使用QML为GridView中的每个项目制作淡入动画,javascript,qt,animation,gridview,qml,Javascript,Qt,Animation,Gridview,Qml,每次gridview的模型更改时,我都会尝试制作淡入动画。 我试图利用链接中提到的示例: 但我正试着在ADD的附加信号上做这件事 是否有可能或是否有我可以使用的解决方法 下面是我的代码 GridView{ id:productGView height: 100 width: 100 anchors{ left: parent.left; top: pa
GridView{
id:productGView
height: 100
width: 100
anchors{
left: parent.left; top: parent.top;
}
cellHeight:20;
cellWidth: 20;
keyNavigationWraps :true
delegate: Image{
id:gridDel
height: productGView.cellHeight
width: productGView.cellWidth
source:(productGView.currentIndex==index)?("item_h.png"):("item_n.png")
GridView.onAdd: SequentialAnimation {
PropertyAction { target: gridDel; property: "GridView.delayRemove"; value: true }
NumberAnimation { target: gridDel; property: "scale"; to: 0; duration: 250; easing.type: Easing.InOutQuad }
PropertyAction { target: gridDel; property: "GridView.delayRemove"; value: false }
}
GridView.onRemove: {
core.log("Del | onRemove | index = "+index)
}
Component.onCompleted: {
core.log("Del | onCompleted | index = "+index)
}
}
snapMode: GridView.SnapToRow
boundsBehavior: Flickable.DragOverBounds
}
提前感谢在将项目添加到视图时,它不需要防止删除,因此您可以通过删除两个
属性动作
来简化GridView.onAdd
处理程序,然后SequentialAnimation
也变得不必要
在代码中,NumberAnimation
将缩放设置为0
,从而使单个代理无限小。试试这个:
delegate: Image {
..
..
scale: 0 /* When a delegate is created, scale is initially zero */
GridView.onAdd: NumberAnimation {
target: gridDel
property: "scale"
to: 1 /* When the delegate is added to the view, */
/* the scale will be animated to 1 */
duration: 250
easing.type: Easing.InOutQuad
}