I would like to move the cursor to a given x,y coordinates of the MapCanvas.
Is there an easy way to do this using PyQGIS?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityYou can move cursor like that:
from PyQt4.QtGui import *
from PyQt4.QtCore import *
cursor = QCursor()
cursor.setPos(100, 200)
It moves your cursor to point 100,200 in your screen. If you want to get coordinate of a point on the map canvas, you need to translate them:
# coordinates of point on map canvas
point = QPoint(100,100)
# translate widget coordinates to global screen coordinates
global_point = iface.mapCanvas().mapToGlobal(QPoint(100,100))
# set cursor to these coords
cursor.setPos(global_point.x(), global_point.y())
mapToGlobal()
, eh? how cool is that!!! answers my question too: gis.stackexchange.com/questions/217164/…
Nov 10, 2016 at 11:01
QgsPointXY(34.364272,44.61443)
to QPoint(x,y)
Apr 18 at 13:34