Flickable 内的 MouseArea 阻止它轻弹 [英] MouseArea inside Flickable is preventing it from flicking
问题描述
我正在使用 MouseArea 实现手势捕捉器(向左/向右滑动).它应该在具有垂直 flickableDirection 的 Flickable 内工作.此外,它应该以视觉堆栈顺序将鼠标事件传播到它下面的其他元素.问题是 propagateComposedEvents 设置为 true 的子 mouseArea 在精确的一次点击之前阻止了任何父级的轻弹.第一次点击后,它工作正常.这是显示这一点的简化代码.
I'm implementing gesture catcher (swipe left/right) with MouseArea. It should work inside Flickable with vertical flickableDirection. Also it should propagate mouse events to other elements beneath it in visual stack order. The problem is that child mouseArea with propagateComposedEvents set to true is blocking any parent's flicks before exact one click is made. After first click is made it's working correctly. Here is simplified code that is showing this.
import QtQuick 2.4
import QtQuick.Window 2.2
Window {
id: __root
visible: true
width: 460; height: 640
Flickable {
id: mainFlickable
width: parent.width
height: parent.height
contentHeight: column.height
flickableDirection: Flickable.VerticalFlick
MouseArea {
anchors.fill: parent
propagateComposedEvents: true
z: 1
}
Column {
id: column
width: parent.width
Repeater {
model: 5
Rectangle {
width: __root.width
height: 200
color: "yellow"
border.width: 2
MouseArea {
anchors.fill: parent
onClicked: {
console.log("clicked")
}
}
}
} //repeater
} //column
} //flickable
} //window
我花了相当多的时间来解决这个问题,如果您能提供任何帮助,我将不胜感激.提前致谢!
I spent quite some time trying to fix this and will appreciate any help. Thanks in advance!
推荐答案
我发现 MouseArea 中的以下信号处理程序可以解决此问题,并且不会破坏我的代码:
I found that following signal handler in MouseArea is a workaround for this and don't break my code:
onReleased: {
if (!propagateComposedEvents) {
propagateComposedEvents = true
}
}
propagateComposedEvents
应在声明中设置为 false
(或省略).
propagateComposedEvents
should be set to false
on the declaration (or ommited).
感谢大家的努力!
这篇关于Flickable 内的 MouseArea 阻止它轻弹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!