Qt/QML SwipeDelegate 在移动设备(Android、iOS)上无法正常工作
Posted
技术标签:
【中文标题】Qt/QML SwipeDelegate 在移动设备(Android、iOS)上无法正常工作【英文标题】:Qt/QML SwipeDelegate doesn't work properly on mobile devices (Android, iOS) 【发布时间】:2017-03-17 10:37:09 【问题描述】:我是 Qt/QML 编程的新手,正在尝试让以下示例在移动设备上正常运行。当我尝试“向右滑动”然后点击删除按钮时,不会删除“Listview-item”。在桌面上一切正常,但在移动设备上它不能正常工作。谁能帮我解决我的问题?
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"
【问题讨论】:
【参考方案1】:您可以在矩形内添加带有 onClicked 事件的 MouseArea。这是一个例子:
background: Rectangle
color: deleteLabel.SwipeDelegate.pressed ? Qt.darker("tomato", 1.1) : "tomato"
MouseArea
anchors.fill: parent
onClicked: listView.model.remove(index)
【讨论】:
以上是关于Qt/QML SwipeDelegate 在移动设备(Android、iOS)上无法正常工作的主要内容,如果未能解决你的问题,请参考以下文章
qt qml中PropertyAnimation的几种使用方法
Qt Qml,在 iOS 上将地图(OSM Mapbox Mapboxgl)嵌入到 QQuickWidget C++ 对象中