2

I wish to apply my action on pyqgis (in a plugin).

In my QGIS plugin, I created an action that I apply to a certain layer. The action appears well on my layer but it is not automatically applied, I have to do it manually.

I think I should use the run() function of the QgsAction class.

layer_hypothese = iface.activeLayer()
action_layer_hypothese = layer_hypothese.actions()
actionDescription = 'Graph radar '
actionCode = 'from qgis.utils import iface; iface.messageBar().pushMessage("Feature ID: [% $id %]", 0)'
scope = {'Feature','Layer','Canvas','Field'}


action_graphique = QgsAction(QgsAction.GenericPython,actionDescription,actionCode,'',False,'',scope)
action_layer_hypothese.addAction(action_graphique)
  • You can run with selectedFeatures using doActionFeature but if you want call this action when canvas is clicked need capture this event overwriting canvasReleaseEvent and create a custon function for select feature inside this click etc – Fran Raga Jul 11 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.