How to get Screen Coordinates of a QML Item?
-
wrote on 9 Sept 2013, 20:55 last edited by
I have a QQuickView that displays a scene. I want to know at which screen coordinate a certain QML item is located at. I know from inside the QML I can call
@
myItem.mapToItem(null, myItem.x, myItem.y)
@
But I want to give the result (QVariantMap) to a C++ Q_INVOKABLE method that displays a dialog at the position of myItem.x,myItem.y
It seems I need to map the QQuickView coordinates to Screen coordinates. But how? -
wrote on 13 Sept 2013, 14:58 last edited by
Perhaps this function:
@Item::mapToItem(Item item, real x, real y)@documentation:
"http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-item.html":http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-item.html -
wrote on 13 Sept 2013, 19:51 last edited by
uhmmm didn't I wrote I use this already?
-
wrote on 13 Sept 2013, 19:59 last edited by
Did you read the documentation? Are you having trouble using the function or don't you understand what to do with the results?
-
wrote on 17 Sept 2013, 01:35 last edited by
I recall doing this before. I believe you want
@myItem.mapToItem(null, 0, 0)@
Which is the top left corner of myItem relative to myItem. If you use
@myItem.mapToItem(null, myItem.x, myItem.y)@
myItem.x and myItem.y are the x/y coordinates relative to myItem's parent object.
-
wrote on 13 Jun 2014, 08:21 last edited by
None of these are actually screen coordinates. They are all relative to the main window which could be anywhere.