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)@
uhmmm didn't I wrote I use this already?
Did you read the documentation? Are you having trouble using the function or don't you understand what to do with the results?
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.
None of these are actually screen coordinates. They are all relative to the main window which could be anywhere.