Inspired by the RectangleMapTool provided in Qgis documentation (https://docs.qgis.org/3.34/en/docs/pyqgis_developer_cookbook/canvas.html#writing-custom-map-tools) , I made a CircleMapTool that draws a circle when moving cursor on the canvas :
I would like to detect mouse moves out of canvas, in order to avoid this situation (circle is "stucked" on canvas border)
Code extract:
class CircleMapTool(QgsMapToolEmitPoint):
def __init__(self, canvas):
QgsMapToolEmitPoint.__init__(self, canvas)
self.rubberBand = QgsRubberBand(canvas, QgsWkbTypes.PolygonGeometry)
self.rubberBand.setColor(QColor(255, 0, 0))
self.rubberBand.setWidth(2)
def canvasMoveEvent(self, e):
# out of canvas events are not raised
point = self.toMapCoordinates(e.pos())
self.rubberBand.movePoint(point)
I would like to avoid QObject.eventFilter, if possible
eventFilter
? it seems like a good way to achieve this.