1

I apologize if this question was already answered, but I found a lot of examples on how to set the QGIS maptool in a application from scratch, but not inside QGIS (in a plugin).

In the examples I found, the author creates a toolbar icon, an action and a custom QgsMapTool action.

What I want to do, is something (that I thought it was) more simple: - I want to set the canvas maptool to be the QGIS native zoom in (QgsMapToolZoom); basically the same that happens, when the user clicks the zoom in icon on the QGIS toolbar; Note that I don't want to zoom in like this:

canvas.zoomIn()

But I want to set the current mapTool to zoom in, and let the user zoom instead.

I implemented it as follows:

        canvas=self.eaf.iface.mapCanvas()

        zoomTool=QgsMapToolZoom(canvas, False)

        canvas.setMapTool(zoomTool)

However this fails. QGIS unsets the current maptool (lets say, for instance pan) and sets a void maptool (represented by an arrow cursor and no action) I added this piece of code, after initializing the zoom tool:

        zoomTool=QgsMapToolZoom(canvas, False)

        act=zoomTool.action()
        print act            

And found out that the action of the tool is empty (None). I don't want to start an action, because I would like to use the native QGIS actions that are associated to the QGIS toolbar icons. How can I access the native QGIS zoom action and force my maptool to use it?

Thanks in advance for your time

2

You get access to the native mpatool actions via several iface.actionXXX() methods which you can trigger. For your case this is

iface.actionZoomIn().trigger()

or

iface.actionZoomOut().trigger()
  • @Matthias Kuhn I followed your advice and got the same thing going for iface.actionAddFeature().trigger() in qgis 2.0. Have you had any experience, however, with this not working for qgis 2.4 as i have? If so, I've asked this question and am wondering if you have insight: gis.stackexchange.com/questions/106994/… – user25976 Jul 30 '14 at 23:49

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.