4

In my QGIS python plugin I use self.iface.actionSelectRectangle().trigger() to select features. I also have a button which changes the attributes of the selected features.

Is there a way instead of using a button to change the attributes, to call the method automatically after a selection was made using self.iface.actionSelectRectangle().trigger().

2

An answer is here : How to define an event for features selected in mapcanvas in qgis using python

You can connect your function to the selectionChanged signal of your vector layer

Example code from the related answer:

lyr=iface.activeLayer()
def myFunction(selFeatures):
   print str(len(selFeatures)) + " features were selected: " + str(selFeatures)

lyr.selectionChanged.connect(myFunction)

Each time you change the selection of your vector layer, myFunction is run.

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.