首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QML,Qt 5.11:用SwipeView代替SwipeDelegate

QML,Qt 5.11:用SwipeView代替SwipeDelegate
EN

Stack Overflow用户
提问于 2018-06-30 08:43:52
回答 1查看 391关注 0票数 1

我有一个SwipeView,里面有一个带SwipeDelegate的中继器。问题是,有时当我滑动转发器项目时,它会注册为SwipeDelegate上的滑动,这是我想要的,但有时它会注册为SwipeView上的滑动,并更改页面,这是我不想要的。为了清晰起见,下面的代码。

有没有什么办法可以让SwipeDelegate始终优先于SwipeView?或者实现这种类型的嵌套滑动区域只是一种糟糕的做法?

我尝试使用z-order,如代码所示,但无济于事。

代码语言:javascript
复制
TabBar {
    id: appTabBar
    contentContainer: swipeView

    TabButton {
        text: "Add History"
    }

    TabButton {
        text: "View History"
    }
}

QC2.SwipeView {
    id: swipeView
    anchors.top: appTabBar.bottom
    anchors.bottom: parent.bottom
    width: parent.width
    clip: true
    z: 1

    Item {}

    Item {

        Column {
            id: table
            width: parent.width
            spacing: 3

            Repeater {
                id: foodTableRepeater
                height: dp(20)
                model: []
                delegate: QC2.SwipeDelegate {
                    id: swipeDelegate
                    width: parent.width

                    Rectangle {
                        height: parent.height
                        width: parent.width
                        color: (index % 2 === 0) ? "#D3F2FF" : "#FFFFFF"
                        border.color: "blue"
                        border.width: dp(1)
                        z: 2

                        Row {
                            height: parent.height
                            width: parent.width
                            AppText {
                                id: date
                                leftPadding: dp(10)
                                width: parent.width
                                anchors.verticalCenter: parent.verticalCenter
                                text: JSFuns.getLocaleDateTime(app.locale, modelData[2], app.use_24)
                            }
                        }
                    }

                    swipe.right: QC2.Label {
                        id: deleteLabel
                        verticalAlignment: QC2.Label.AlignVCenter
                        padding: 5
                        width: parent.width * 0.4 / 3
                        height: parent.height
                        anchors.right: parent.right
                        z: 3
                        Icon {
                            width: parent.width
                            anchors.verticalCenter: parent.verticalCenter
                            icon: IconType.close
                            size: parent.height
                            color: "red"
                        }

                        QC2.SwipeDelegate.onClicked: console.debug(index)

                        background: Rectangle {
                            color: deleteLabel.QC2.SwipeDelegate.pressed ?
                                       Qt.darker(app.color_secondary_light, 1.1) :
                                       app.color_secondary_light
                        }
                    }
                }
            }
        }   
    }
}
EN

回答 1

Stack Overflow用户

发布于 2018-07-01 02:30:20

我想我得到了一个修复方法,似乎效果很好。我按如下方式修改了SwipeDelegate:

代码语言:javascript
复制
delegate: QC2.SwipeDelegate {
    id: swipeDelegate
    width: parent.width
    onPressed: swipeView.interactive = false // New line
    onCanceled: swipeView.interactive = true // New line

这两行代码只是简单地打开和关闭SwipeView,在与SwipeDelegate交互时将其关闭,并在用户完成交互时重新打开。

到目前为止,唯一的缺点是我不能通过向右滑动SwipeDelegate来使用SwipeView。然而,这是非常次要的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51110849

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档