[Qgis-developer] How to add an action into a layer through python
lrssvtml at gmail.com
Sun Apr 16 12:58:28 PDT 2017
On Fri, Apr 14, 2017 at 10:31 PM, Luca Mandolesi <mandoluca at gmail.com> wrote:
> I would to know if it's possibile to add a python action into a layer
> charged inside layer registry? There is a method inside pyQgis API?
sure, it is possible. With 2.x version the below example should be working:
>>> vl = iface.activeLayer()
>>> actions = vl.actions()
>>> actionName = 'Show feature id'
>>> actionContent = 'from qgis.utils import iface; iface.messageBar().pushMessage("Feature ID: [% $id %]", 0)'
>>> actions.addAction(QgsAction.GenericPython, actionName, actionContent)
Since QGIS 3 the code for actions was revamped, please see
IRC: lrssvt on freenode
More information about the Qgis-developer