如何在QML中检测Window {}外的点击次数?
Rectangle {
id: topLevel
height: 400; width: 400
Window {
id: windowObj
color: "blue"
height: 200; width: 200
onActiveChanged { console.trace(); visible = false; }
}
Component.onCompleted: windowObj.visible = true
}
假设我点击了topLevel
以外windowObj
的部分内容。
onActiveChanged
适用于Windows但不适用于MAC。
{Using: QtQuick 2.1, QtQuick.Window 2.1, QML/Qt 5.2.0}
答案 0 :(得分:0)
将MouseArea放在topLevel矩形中,让事件通过
Rectangle {
id: topLevel
MouseArea{
anchors.fill : topLevel
propagateComposedEvents : true
onClicked : console.log("clickoutside");
}
Window {
id: windowObj
color: "blue"
height: 200; width: 200
onActiveChanged { console.trace(); visible = false; }
}
}