With PyQGIS how can I convert absolute screen coordinates (say, 123,456
) into map coordinates of the iface.mapCanvas
?
It would be no problem if I had screen coordinates relative to the iface.mapCanvas.viewport()
, since iface.mapCanvas.viewport().geometry()
gives me sth like QRect(2,2,2198, 1090)
and iface.mapCanvas().extent()
gives me a QgsRectangle
with xmin,xmax,ymin,ymax
, so (leaving projection issues out of the scope) the conversion would be simple.
But since the absolute position of the mapCanvas
may vary with toolbar positions or layer windows width, the question reduces to 'how to derive the absolute screen position of the map canvas?'.