QgsMapToolEmitPoint 类继承QgsMapTool,而QgsMapTool 又具有canvasDoubleClickEvent方法。此方法是虚拟的,因此您可以在子类中重新实现它并发出自定义信号。尝试这样的事情:
class MapToolEmitPoint(QgsMapToolEmitPoint):
canvasDoubleClicked = QtCore.pyqtSignal(object, object)
def canvasDoubleClickEvent(self, event):
point = self.toMapCoordinates(event.pos())
self.canvasDoubleClicked.emit(point, event.button())
super(MapToolEmitPoint, self).canvasDoubleClickEvent(event)
该canvasDoubleClicked
信号已被赋予与现有信号相同的签名canvasClicked
,因此您应该能够以相同的方式使用它。
编辑
为了清楚起见,上面的类打算像这样使用:
maptool = MapToolEmitPoint(self.canvas)
self.canvas.setMapTool(maptool)
maptool.canvasDoubleClicked.connect(self.handleDoubleClick)
....
def handleDoubleClick(self, point, buttons):
# do stuff with point and buttons
...