In continuity in my question How to add a legend to a canvas in a standalone PyQGIS application? > In every addition of a new layer in my standalone application, the legend lengthens and becomes overloaded. So I would like to know how to remove one or several layers with his(their) legend(s). Sorry for my english.
Asked
Active
Viewed 862 times
1
1 Answers
1
your question isn't a QGIS question, but a QT question. Legend tree is managed by QgsLegendTreeView that is a QTreeView. So all what you need is to browse you tree an hide rows to compact your legend with http://doc.qt.io/qt-4.8/qtreeview.html#setRowHidden If you simply want to remove a layer from QGIS (standalone or not) simply unregister it from QgsMapLayerRegistry with QgsMapLayerRegistry.instance().removeMapLayer(layerId)
Luigi Pirelli
- 2,013
- 14
- 19
QgsMapLayerRegistry.instance().removeMapLayer(id). I keep getting segmentation faults when removing/adding layers (like here: http://osgeo-org.1560.x6.nabble.com/PyQGIS-Problems-with-the-layerWasAdded-SIGNAL-td4118064.html). Could you confirm it? – Germán Carrillo Apr 14 '15 at 12:59