我添加了添加,删除和移位到我的QML ListView
的转换,除了页脚之外,它们按预期工作。
页脚只是跳转到目标位置,而委托项目仍在动画中。所以问题就在于:如何将过渡应用于QML ListView.footer
?这甚至可能吗?
这是一些示例代码。评论说明的行是我尝试过但没有工作的东西。
import QtQuick 2.6
import QtQuick.Controls 1.5
ApplicationWindow {
visible: true; width: 640; height: 480
title: qsTr("Hello World")
menuBar: MenuBar {
Menu {
title: "List"
MenuItem { text: "Add Peach"; onTriggered: fruitModel2.append({"name":"Peach", "cost":5.00}) }
MenuItem { text: "Clear Fruits"; onTriggered: fruitModel2.clear() }
MenuItem { text: "Remove Peach"; onTriggered: fruitModel2.remove(2) }
}
}
ListModel {
id: fruitModel2
ListElement { name: "Apple"; cost: 2.45 }
ListElement { name: "Orange"; cost: 3.25 }
ListElement { name: "Banana"; cost: 1.95 }
}
ListView {
id: theList
anchors.fill: parent; model: fruitModel2; spacing: 5
onHeightChanged: console.debug("heigt:", height)
// Behavior on height { NumberAnimation {duration: 1000} }
// Behavior on contentHeight { NumberAnimation {duration: 1000} }
delegate: Row {
anchors.horizontalCenter: parent.horizontalCenter
Text { text: "Fruit: " + name }
Text { text: "Cost: $" + cost }
}
add: Transition {
// ParallelAnimation {
// NumberAnimation { property: "y"; duration: 1000}
NumberAnimation { property: "opacity"; from: 0; to: 1; duration: 1000}
// }
}
displaced: Transition { NumberAnimation { property: "y"; duration: 1000} }
remove: Transition { NumberAnimation { property: "opacity"; from: 1; to: 0; duration: 1000} }
footer: Rectangle {
width: parent.width
height: 40
color: "darkred"
// Behavior on y { NumberAnimation {duration: 1000} }
}
}
}