0
我是Qt/QML編程的新手,並試圖讓以下示例在移動設備上正常運行。當我嘗試「向右滑動」,然後點擊刪除按鈕時,「Listview-item」不會被刪除。在桌面上一切正常,但在移動設備上無法正常工作。任何人都可以幫我解決我的問題嗎?Qt/QML SwipeDelegate在移動設備(Android,iOS)上無法正常工作
import QtQuick 2.7
import QtQuick.Controls 2.0
ApplicationWindow {
id: appWindow
visible: true
ListView {
id: listView
anchors.fill: parent
model: ListModel {
ListElement { name: "Swipe Delegate - Test 1" }
ListElement { name: "Swipe Delegate - Test 2" }
ListElement { name: "Swipe Delegate - Test 3" }
ListElement { name: "Swipe Delegate - Test 4" }
}
delegate: SwipeDelegate {
id: swipeDelegate
text: model.name
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
}
}
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"
}
}
}
}
}
謝謝你,它工作得很好 –