I'm developing a custom GIS application using PyQgis API.

How can I let the user select features on the map using Maptools? I would like to replicate the select feature there in Qgis to make the selection on click of a button. My understanding is to use layer.selectedFeatures() function , but I am not sure of how to add the Selection Maptool to the mapcanvas and toolbar.

  • Please keep to the site format of only ONE question per thread. I'll remove the second one, please repost it.
    – underdark
    Oct 12, 2012 at 10:35

1 Answer 1


The selection map tools are not part of the qgis libs. You therefore have to reimplement the behavior if you are writing a custom app.

Maptool implementation

You will have to subclass qgis.gui.QgsMapTool and implement the canvasPressEvent, canvasMoveEvent and then modify the layer selection according to this.

You can have a look at the source files of the existing selection maptools ( e.g. qgsmaptoolselectpolygon.cpp ). They are C++ code, but pretty simple and should explain the concept.

Add to the mapcanvas

You will have to call the method setMapTool of your QgsMapCanvas instance and pass an instance of your own selection map tool as parameter.

myMapcanvas.setMapTool( mySelectionTool )


You have to create an action and connect its triggered signal to a method (slot) where you will set the map tool as outlined in the last paragraph.

  • The link for the C++ code is broken. Could you please update it?
    – wondim
    Jun 20, 2018 at 22:59

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.