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?

1 Answer 1


You 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())
  • 1
    +1, I spent a little time trying to find this but couldn't. Also great that you added a translation for the map canvas coordinates =)
    – Joseph
    Jul 21, 2015 at 9:36
  • mapToGlobal(), eh? how cool is that!!! answers my question too: gis.stackexchange.com/questions/217164/… Nov 10, 2016 at 11:01
  • Hey! Is that possible to convert map point to canvas point? I mean for example QgsPointXY(34.364272,44.61443) to QPoint(x,y) Apr 18 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.