是否可以像在 webOS 上一样从 QML 中的 ListView 中删除项目,即在滑动条目后有“取消”和“删除”。
我想使用 Qt 4.7(所以 QtQuick 1.1)
QtQuick 中没有可以处理手势信号的默认组件。有一个 Qt 实验室项目引入了一个 GestureArea 可以做你想做的事。它没有与 QtQuick 1.1 一起打包,我不确定它的当前状态,但请随意尝试一下。http://blog.qt.digia.com/blog/2010/10/05/getting-in-touch-with-qt-quick-gestures-and-qml/ 否则,虽然 Qt 本身确实有,但没有 QML 解决方案手势编程支持http://qt-project.org/doc/qt-4.7/gestures-overview.html
帮助中有delete方法,看这个例子
ListView {
id: listView
anchors.fill: parent
model: ListModel {
ListElement { sender: "Bob Bobbleton"; title: "How are you going?" }
ListElement { sender: "Rug Emporium"; title: "SALE! All rugs MUST go!" }
ListElement { sender: "Electric Co."; title: "Electricity bill 15/07/2016 overdue" }
ListElement { sender: "Tips"; title: "Five ways this tip will save your life" }
}
delegate: SwipeDelegate {
id: swipeDelegate
text: model.sender + " - " + model.title
width: parent.width
ListView.onRemove: SequentialAnimation {
PropertyAction {
target: swipeDelegate
property: "ListView.delayRemove"
value: true
}
NumberAnimation {
target: swipeDelegate
property: "height"
to: 0
easing.type: Easing.InOutQuad
}
PropertyAction {
target: swipeDelegate
property: "ListView.delayRemove"
value: false
}
}
onClicked: {
swipe.complete=false
}
swipe.right: Label {
id: deleteLabel
text: qsTr("Delete")
color: "white"
verticalAlignment: Label.AlignVCenter
padding: 12
height: parent.height
anchors.right: parent.right
SwipeDelegate.onClicked: listView.model.remove(index)
background: Rectangle {
color: deleteLabel.SwipeDelegate.pressed ? Qt.darker("tomato", 1.1) : "tomato"
}
}
}
}