I want to know how to check for a mouse click in QGIS. I am trying to write a python plugin and want to provide functionality similar to the "Select Single Feature" tool that already exists in QGIS.
I checked the QGIS api docs and found
QgsMapCanvas::CanvasProperties::mouseButtonDown
This sounds promising. I have a QgsMapCanvas object but I can't see how to access the mouseButtonDown attribute.
I am completely new to the QGIS API.
Best Answer
The best way to make a new tool like the Select Single Feature tool is to inherit from the
QgsMapTool
class. When your tool is active, which can be set usingQgsMapCanvas::setMapTool
, any keyboard or click events the canvas gets will be passed onto your custom tool.Here is a basic
QgsMapTool
classYou can do what you need in
canvasReleaseEvent
, etcTo set this tool active you just do: