1

Working on a new plugin I am trying to connect a custom function to the mouse right-clic signal while using the polygon selecting maptool.

I have activated the maptool through :

def run(self):
    self.iface.actionSelectPolygon().trigger()

And would now like to connect my selectSite function to a canvasReleaseEvent or similar signal. From an interesting tutorial here I adapted the code and tried the line below which failed :

def run(self):
    self.iface.actionSelectPolygon().trigger()
    result = QObject.connect(self.canvas.mapTool(), SIGNAL("canvasReleaseEvent()"), self.selectSite)

def selectSite(self):
    QMessageBox.information( self.iface.mainWindow(),"Info", "in selectSite function" )

Is there another way around by connecting to a more generic Qt mouse click signal ?

Any ideas or hints on how I can achieve my goal ?

  • iface.mapCanvas() is a QgsMapCanvas and it always generate events. Is it what you are looking for? – Luigi Pirelli Mar 20 '15 at 20:56
  • Thanks for helping Luigi. It would be great if the QgsMapCanvas had a "canvasReleaseEvent" Signal like QgsMapTool but I don't see it in the API. Do you know a way of connecting to such a signal ? Although there is a mapCanvasRefreshed Signal I could use as a workaround. – Fuzl Mar 21 '15 at 11:05
  • are you shure? QgsMapCanvas is a QGraphicView (as in documentation) that has release event. And in the qgsmapcanvas.h and in cpp code it is implemented: qgis.org/api/qgsmapcanvas_8h_source.html#l00506 and qgis.org/api/… – Luigi Pirelli Mar 21 '15 at 12:39
  • @LuigiPirelli There is indeed a keyReleased event working with QKeyEvent, but no "clicReleaseEvent" or so working with QMouseEvent. It seems from doc-snapshots.qt.io/4.8/qkeyevent.html the first one is only related to keyboard. – Fuzl Mar 21 '15 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.