我正在尝试在 QML 的矩形中使用 Mousearea。我得到 onPressed、OnCLicked、onDoubleClicked 和 onPositionChanged。
但是,QML 没有收到 onReleased 事件。你们能告诉我,为什么它不起作用?我的代码如下:
Rectangle {
width: parent.width
height: 500
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
preventStealing: true
onPositionChanged: {
// console.log("onPositionChanged mouse X", mouse.x)
// console.log("onPositionChanged mouse Y", mouse.y)
mouse.accepted = false;
}
onClicked:{
console.log("onClicked mouse X", mouse.x)
console.log("onClicked mouse Y", mouse.y)
mouse.accepted = false;
}
onDoubleClicked:{
console.log("onDoubleClicked mouse X", mouse.x)
console.log("onDoubleClicked mouse Y", mouse.y)
mouse.accepted = false;
}
onExited:{
console.log("onExited")
}
onPressAndHold:{
console.log("onPressAndHold mouse X", mouse.x)
console.log("onPressAndHold mouse Y", mouse.y)
mouse.accepted = false;
}
onPressed:{
console.log("onPressed mouse X", mouse.x)
console.log("onPressed mouse Y", mouse.y)
mouse.accepted = false;
}
onReleased:{
console.log("onReleased mouse X", mouse.x)
console.log("onReleased mouse Y", mouse.y)
mouse.accepted = false;
}
onCanceled:{
console.log("onCanceled mouse X", mouse.x)
console.log("onCanceled mouse Y", mouse.y)
mouse.accepted = false;
}
}
}