Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML Screen Coordinates of Component

Tags:

qt

qt-quick

qml

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?

like image 927
Paul Carlisle Avatar asked Jan 30 '14 10:01

Paul Carlisle


1 Answers

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.

like image 190
Simon Warta Avatar answered Oct 07 '22 00:10

Simon Warta