我有一个SwipeView,里面有一个带SwipeDelegate的中继器。问题是,有时当我滑动转发器项目时,它会注册为SwipeDelegate上的滑动,这是我想要的,但有时它会注册为SwipeView上的滑动,并更改页面,这是我不想要的。为了清晰起见,下面的代码。
有没有什么办法可以让SwipeDelegate始终优先于SwipeView?或者实现这种类型的嵌套滑动区域只是一种糟糕的做法?
我尝试使用z-order,如代码所示,但无济于事。
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
}
}
}
}
}
}
}发布于 2018-07-01 02:30:20
我想我得到了一个修复方法,似乎效果很好。我按如下方式修改了SwipeDelegate:
delegate: QC2.SwipeDelegate {
id: swipeDelegate
width: parent.width
onPressed: swipeView.interactive = false // New line
onCanceled: swipeView.interactive = true // New line这两行代码只是简单地打开和关闭SwipeView,在与SwipeDelegate交互时将其关闭,并在用户完成交互时重新打开。
到目前为止,唯一的缺点是我不能通过向右滑动SwipeDelegate来使用SwipeView。然而,这是非常次要的。
https://stackoverflow.com/questions/51110849
复制相似问题