android - Qt/QML SwipeDelegate 在移动设备(Android、iOS)上无法正常工作

标签 android ios qt qml qtquickcontrols2

我是 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"
                }
            }
        }
    }
}

最佳答案

您可以在矩形内添加一个带有 onClicked 事件的 MouseArea。这是示例:

 background: Rectangle {
                color: deleteLabel.SwipeDelegate.pressed ? Qt.darker("tomato", 1.1) : "tomato"
                MouseArea {
                    anchors.fill: parent
                    onClicked: listView.model.remove(index)
                }
}

关于android - Qt/QML SwipeDelegate 在移动设备(Android、iOS)上无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42855246/

相关文章:

java - 用于测试的 Android 手机

ios - TableViewCell 中的 Swift 3 UISwitch 在滚动时丢失状态

c++ - 删除 QMap 的前 5 个元素

c++ - 如何用触摸数据模拟鼠标点击?

ios - 在 iOS 游戏中为排行榜创建唯一用户

c++ - Qt C++ 从 QTextEdit 创建对象

java - 当我尝试通过我的应用程序注册时,我没有收到任何回复

java - Dagger 2 中的作用域

android - 获取导致 SQLiteConstraintException 的约束名称

ios - 使用未声明的类型 'UIViewController'