Retrieving an items position in global screen coordinates and keep it up to date
-
Hi all,
what's the best way to retrieve the position of an item in global screen coordinates and get notified when it changes (i.e. to show the position in a label)?
MainWindow { Item { Item { Text { // text: x coordinate + ", " + y coordinate } } } }
The text should get updated when the MainWindow is moved, one of the parent items or the text item itself.
Cheers!
-
Hi all,
what's the best way to retrieve the position of an item in global screen coordinates and get notified when it changes (i.e. to show the position in a label)?
MainWindow { Item { Item { Text { // text: x coordinate + ", " + y coordinate } } } }
The text should get updated when the MainWindow is moved, one of the parent items or the text item itself.
Cheers!
@DuBu
there is simply no generic way to achieve that (in QML) -
@DuBu
there is simply no generic way to achieve that (in QML)@raven-worx To bad. Thx, anyway!
-
To do it on demand you can use : http://doc.qt.io/qt-5/qml-qtquick-item.html#mapToGlobal-method
If you absolutely need it updated live, I believe it's possible to do it in c++ by listening to all the ancestors
xChanged
,yChanged
,widthChanged
,heightChanged
signals up to the root window.or you can call
mapToGlobal
on a timer. -
To do it on demand you can use : http://doc.qt.io/qt-5/qml-qtquick-item.html#mapToGlobal-method
If you absolutely need it updated live, I believe it's possible to do it in c++ by listening to all the ancestors
xChanged
,yChanged
,widthChanged
,heightChanged
signals up to the root window.or you can call
mapToGlobal
on a timer. -
@GrecKo I tried it with mapToGlobal, mapFromGlobal, mapToItem, mapFromItem already with no luck.
But now that you mentioned mapToGlobal again I gave it another try: Now it works and the timer was also a good hint. It's just a hack but anyway.
Thanks!