1

I have create a custom map tool for QGIS 2.6, implementing a canvasReleaseEvent and canvasPressEvent. I can't though get the signals to work on one single mouseclick (I have to click twice).

My map tool was implemented like this:

class IdentifyGeometryTool(QgsMapToolIdentify, QgsMapTool):
    def __init__(self, canvas):
        self.canvas = canvas
        QgsMapToolIdentify.__init__(self, canvas)

    geomIdentified = pyqtSignal(['QgsVectorLayer', 'QgsFeature'])
    def canvasReleaseEvent(self, mouseEvent):
        results = self.identify(mouseEvent.x(), mouseEvent.y(), self.ActiveLayer, self.VectorLayer)
        if len(results) > 0:
            self.geomIdentified.emit(results[0].mLayer, results[0].mFeature)

    canvasClicked = pyqtSignal(['QgsPoint', 'Qt::MouseButton'])
    def canvasPressEvent(self, mouseEvent):
        pnt = self.toMapCoordinates(mouseEvent.pos())
        self.canvasClicked.emit(pnt, mouseEvent.button())

It was then created and connected to a couple of functions in a plugin:

class myPluginClass:

    def __init__(self, iface):
        self.clickTool = IdentifyGeometryTool(self.canvas)

    def initGui(self):
        self.clickTool.canvasClicked.connect(self.firstFunction)
        self.clickTool.geomIdentified.connect(self.secondFunction)

    def firstFunction(self, point):
        do stuff

    def secondFunction(self, layer, feature):
        do more stuff

Clicking the canvas (on a feature on the active layer) the first time connects to firstFunction and clicking one more time connects to a secondFunction. What can I do to call each function in one mouse click and release?

4
  • Couldn't reproduce it here (QGIS .2.6). Do you still have the issue? Feb 7 '15 at 20:48
  • @gcarrillo yes, I do. Are you able to implement a separate click and release for one single mouse click?
    – user25976
    Feb 9 '15 at 21:15
  • If I get you right, yes. Your code runs fine here. If I click on a feature of the active layer, both firstFunction and secondFunction are called. Feb 9 '15 at 21:21
  • @gcarrillo i'm not getting that--i have to click twice to get to the second function. can you suggest something else that could be going on?
    – user25976
    Feb 10 '15 at 8:26

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.