qml mousearea overlab无法在hoverenable模式下工作

时间:2018-05-03 10:03:40

标签: qt qml qt-quick

我的问题是mouseArea没有传递悬停事件。我该如何解决这个问题?换句话说,我想在下面的例子中一起打印1和2。谢谢。

Window {
visible: true
width: 640
height: 480
MouseArea{
    anchors.fill: parent
    hoverEnabled: true
    preventStealing: true
    propagateComposedEvents: true
    onPositionChanged: console.log("1")
}
MouseArea{
    anchors.fill: parent
    hoverEnabled: true
    preventStealing: true
    propagateComposedEvents: true
    onPositionChanged: {
        console.log("2")
    }
}

1 个答案:

答案 0 :(得分:0)

propagateComposedEvents仅适用于clickeddoubleClickedpressAndHold个事件:

  

此属性保存是否自动组合鼠标事件   传播到与此MouseArea重叠的其他MouseAreas但是   视觉堆叠顺序较低。默认情况下,此属性为   假的。

     

MouseArea包含几个组合事件:clicked,doubleClicked和   按下并按住不动。它们由基本的鼠标事件组成,如按下,   与基本事件相比,可以进行不同的传播。

您可以定义自己的自定义QQuickItem,在MouseArea上安装事件过滤器,或者只是手动通知其他MouseArea悬停事件。