我的代码是这样的:
import QtQuick 2.0
import QtQuick.Window 2.0
Window {
visible: true
width: 500
height: 500
GridView {
id: grid
anchors.fill: parent
cellWidth: 30
cellHeight: 30
model: 120
delegate: Rectangle {
width: grid.cellWidth
height: grid.cellHeight
color: "grey"
}
MouseArea {
anchors.fill: parent
onPressed: console.info(">> PRESSED triggered")
onMouseXChanged: console.info(">> " + mouseX)
onReleased: console.info(">> RELEASED triggered")
preventStealing: true
propagateComposedEvents: true
}
}
}当我按住鼠标键并严格沿X轴移动时,MouseArea中的所有信号都会触发。但当鼠标沿Y轴向上或向下移动时,onMouseXChanged和onReleased信号不会触发。GridView似乎截获了MouseArea的信号,从MouseArea中窃取了它们。我如何让它们协同工作:GridView里面有MouseArea?
发布于 2015-05-13 16:18:59
在MouseArea中将preventStealing设置为true。
此属性保存是否可以从此MouseArea窃取鼠标事件。
如果将MouseArea放置在过滤子鼠标事件(诸如可闪烁)的项目内,则如果手势被父项目识别(例如轻击手势),则可以从MouseArea窃取鼠标事件。如果preventStealing设置为true,则不会有任何项窃取鼠标事件。
https://stackoverflow.com/questions/30208597
复制相似问题