I try to use this code from QGIS 2.x version in QGIS 3.0:
li = iface.legendInterface() li.setLayerVisible(myLayer, False)
I found QgsAnnotation but can not use it.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
In QGIS3 If you run
you get an AttributeError
Traceback (most recent call last): File "C:\OSGEO4~1\apps\Python36\lib\code.py", line 91, in runcode exec(code, self.locals) File "<input>", line 1, in <module> AttributeError: 'QgisInterface' object has no attribute 'legendInterface'
Look at: https://qgis.org/api/api_break.html
QgsLegendInterface was removed. It was replaced by layer tree API (QgsLayerTreeNode class and others). Methods that deal with custom actions in main window's layer tree context menu were moved to QgisInterface: • addLegendLayerAction() moved to QgisInterface::addCustomActionForLayerType() • addLegendLayerActionForLayer() moved to QgisInterface::addCustomActionForLayer() • removeLegendLayerAction() moved to QgisInterface::removeCustomActionForLayerType()
If you want to hide the layer: