Map MouseArea x, y to global
Solved
QML and Qt Quick
-
I am obviously missing something basic here, but I am struggling to map
mouse.x, mouse.y
in aMouseArea
to the global (main window) coordinates.import QtQuick 2.9 import QtQuick.Window 2.2 Window { visible: true width: 640; height: 480 Rectangle { width: 250; height: 30 anchors.centerIn: parent border.color: "black" MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton onClicked: { console.log("mouse x, y = ", mouse.x, mouse.y); var globXY = mapToGlobal(mouse.x, mouse.y); console.log("mouse -> global x, y = ", globXY.x, globXY.y); } } } }
Output:
qml: mouse x, y = 95 11 qml: mouse -> global x, y = 930 516
What am I missing?