3

I'm trying to access the QgsLayerTreeView class through the QgisInterface class in the python plugin I have created. Ultimately I want to be able to return the selected node (group or layer) from the QgsLayerTree.

The issue I'm running into is I don't know how to call it. Most information suggests to use iface as a way to access the interface but it's not recognised when called from the plugin (works fine from the python console in QGIS).

Is there any other way to create an instance of the QgisInterface class? Or is there a way I can import the iface class to work in my plugin?

1 Answer 1

5

Your plugins __init__() method should take the interface as an argument on instantiation, probably under the name iface.

If it is stored as instance variable there via a line like

self.iface = iface

you can then use it in any of your plugin's methods via self.iface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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