How to get Screen Coordinates of a QML Item?
-
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? -
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 -
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.