QML Screen Coordinates of Component
qml, qt, qt-quick
Solution
Component.onCompleted: {
var globalCoordinares = myThing.mapToItem(myThing.parent, 0, 0)
console.log("X: " + globalCoordinares.x + " y: " + globalCoordinares.y)
}
where `myThing.parent` is your main compontent.
Problem
If I have a simple, self-contained QML application, I can get the absolute screen coordinates of a component by saying ``` Component.onCompeted: { var l = myThing.mapToItem(null, 0, 0) console.log("X: " + l.x + " y: " + l.y) } ``` where myThing is the id of any other component in the file. However, if this file gets incorporated into another QML file and the component it defines is reused, I don't get the screen coordinates anymore; I get the local coordinates relative to the component where the statements above are executed. How can I get the absolute screen coordinates of items?