Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using PyQGis API to create a custom application.

How do I allow users to select features with the mouse? Is there a mapTool for this? Surely with a product as powerful as QGis there must be.

Thanks in advance

share|improve this question
Have you looked at It is a tutorial about building a Qgis plugin. – GreyHippo Nov 9 '12 at 13:24

There is a class you can inherit from called QgsMapTool which you can override the mouse events to handle user actions.

Like so:

You can find objects under the mouse click for example using code like this:

searchRadius = (QgsTolerance.toleranceInMapUnits( 5, layer, 
               self.canvas.mapRenderer(), QgsTolerance.Pixels))
        rect = QgsRectangle()
        rect.setXMinimum( point.x() - searchRadius );
        rect.setXMaximum( point.x() + searchRadius );
        rect.setYMinimum( point.y() - searchRadius );
        rect.setYMaximum( point.y() + searchRadius ); layer.pendingAllAttributesList(), rect, True, True)    
        for feature in layer:
             # do something with the feature
share|improve this answer
Could you fix the link please? I think it's broken. – underdark Mar 28 '13 at 16:52
To get the searchRadius you can use now searchRadius = self.canvas.mapUnitsPerPixel() * 5 as toleranceInMapUnits is deprecated now. – bennos Sep 27 '15 at 18:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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