I am currently creating a plugin with PyQGIS. The layers all come from a PostgreSQL database. Now I would like to include a table (without geometry) for a ValueRelation without the table appearing in the layer tree.
How can I programmatically hide a layer using PyQGIS?
By default, I load the layers as follows (without the database connection code):
uri.setDataSource("schema", "table1", None)
lyr_table1= QgsVectorLayer(uri.uri(False), "table1", 'postgres')
QgsProject.instance().addMapLayer(lyr_table1)
How do I get access to the interface of the layer tree and which method can be used for hiding?
lyr_table1.setFlags(QgsMapLayer.LayerFlag(QgsMapLayer.Private))– J. Monticolo Jun 17 '21 at 13:11