Reputation: 143895
I don't understand how mapToGlobal interacts with a multiple screen setup. Is it returning the global position relative to that particular screen, or to the whole desktop?
If I invoke QCursor.setPos(widget.mapToGlobal(widget.geometry().topLeft()) will I always end up with the pointer in the top left corner of the widget, regardless of any multiscreen situation?
Upvotes: 2
Views: 2223
Reputation: 27621
As the docs state for mapToGlobal: -
Translates the widget coordinate pos to global screen coordinates
Since you're mapping from local coordinates, you can actually just use: -
mapToGlobal(QPoint(0,0));
Rather than having to specify the widget's top left position of the geometry.
As for mapping to Global coordinates, from memory, I think the global space is extended across the screens, so two screens at a resolution of 1024 x 768 would give a screen space of 2048 x 768, if arranged side by side.
The docs also state: -
For desktops with multiple screens, the size of the desktop is the union of all the screen sizes
So I would expect mapToGlobal would return a value with respect to the total screen space available, rather than just the screen that the widget resides. If it didn't, it would be quite awkward to handle a widget that was placed between two screens.
Note that you can also use QDesktopWidget for information about the different screens and to check which screen a widget resides upon. It's also useful if you want to place a widget on a specific screen.
Finally, in Qt 5, there's also the QScreen class to query screen properties.
Upvotes: 3