Tuesday 30 May 2017

qgis - Moving cursor using PyQGIS?


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?



Answer



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())

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...