From QGIS 3 Plugin Tutorial I need the example for getting a point geometry from clicking at the map.
So I have a file point_tool.py
:
from qgis.gui import QgsMapTool, QgsMapToolEmitPoint
from PyQt5.QtCore import pyqtSignal
class PointTool(QgsMapToolEmitPoint):
canvasClicked = pyqtSignal('QgsPointXY')
def __init__(self, canvas):
super(self, QgsMapTool).__init__(self, canvas)
def canvasReleaseEvent(self, event):
point_canvas_crs = event.mapPoint()
self.canvasClicked.emit(point_canvas_crs)
And in my plugin:
from .point_tool import PointTool
...
def addFachdatum(self):
self.mapTool = PointTool(self.iface.mapCanvas())
self.iface.mapCanvas().setMapTool(self.mapTool)
self.mapTool.canvasClicked.connect(self.onMapClick)
def onMapClick(point):
logging.warning('onMapClick: '+point.asWkt())
But in QGIS I get the following error:
2021-11-18T12:21:46 WARNING Traceback (most recent call last):
File "C:/Users/sschmidt/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\gga_importer\gga_importer.py", line 420, in addFachdatum
self.mapTool = PointTool(self.iface.mapCanvas())
File "C:/Users/sschmidt/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\gga_importer\point_tool.py", line 9, in __init__
super(self, QgsMapTool).__init__(self, canvas)
TypeError: super() argument 1 must be type, not PointTool
But I don't understand the problem, because it is Python37 and PointTool
is derived from QgsMapToolEmitPoint
and this is QObject
. Who can help please?