[Qgis-user] Fwd: Overriding canvasEvent functions of default map tool PyQGIS.

Mayo Rubiano mayo.rubianoh at gmail.com
Tue Nov 1 11:39:15 PDT 2022


I'm trying to get the mouse position whenever the user clicks the canvas
when using a map tool. I've tried this and it works but only with
custom map tools, not with defaults like: Select features, Add feature,
etc...
This is the script to print in the console the QgsMapMouseEvent.

canvas = iface.mapCanvas()

new_tool = canvas.mapTool()
canvas.unsetMapTool(new_tool)
old_function = new_tool.canvasPressEvent
def canvasPressEvent(mouse):
    old_function(mouse)
    print(mouse)

new_tool.canvasPressEvent = canvasPressEvent
canvas.setMapTool(new_tool)

Is it possible to override functions like canvasMoveEvent
<https://qgis.org/pyqgis/3.22/gui/QgsMapTool.html#qgis.gui.QgsMapTool.canvasMoveEvent>
, canvasPressEvent
<https://qgis.org/pyqgis/3.22/gui/QgsMapTool.html#qgis.gui.QgsMapTool.canvasPressEvent>
on
default tools?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20221101/fa5fb95a/attachment.htm>


More information about the Qgis-user mailing list