This is a follow-up question to my question about how to build a QGIS plugin and link a textbox to the plugin toolbar (Adding textbox to QGIS plugin toolbar?).

In addition to that, I was wondering how to add functions of a Map Tool in order to start a different "mode". By mode, I mean something like a editor mode or the identify tool, where the meaning of mouse clicks, scroll event etc change to fit the current task at hand.

I found an answer to this GIS.SE question (Programatically check for mouse click in PyQGIS?), and tested its functions. It seems to be a good start and can handle a mouse click event, when activated with

tool = PointTool(qgis.iface.mapCanvas())

My questions are:

Both the PointTool(QgsMapTool) and plugin created with QGIS's standard Plugin Builder (and pb_tool) can handle various events. Which events should be handled by the MapTool vs by the Plugin? Is there a convention on this?

Also, how to link the MapTool to the Plugin (or embed the MapTool in the Plugin)? Is there a conventional way?

For example, if I click any button in the plugin toolbar, the mouse icon should change to a different shape. Currently, the mouse is still a magnifying class after I activate the MapTool.

How to properly register the tool when the plugin is activated and restore to the previous tool/mode when, e.g., the plugin toolbar is closed/hidden?

1 Answer 1


You can use virtual QAction from QgsInterface Class. There is for example, actionIdentify() that you can trigger when the user click on your button. It will start the Identify Tool.

For example you can define a function like that (you can add the code you need for your task, like set the layer to work with, selecting features,...):

def myIdentifyTool():

and connect your button to this function like that:


So when you click your button, the Identify tool will be trigger.

Have a look to the QgsInterface class documentation to see all QAction available.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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