Sunday, 2 August 2015

Updating Layer tree after changing symbology with PyQGIS


When I change symbology for a given QgsVectorLayer (QGIS 2.14.16 LTR) by


r=iface.activeLayer().rendererV2()
r.symbol().symbolLayers()[0].setColor(0,0,255,255)

as shown here:


enter image description here



and refreshing the map content by


iface.mapCanvas().refreshAllLayers()

I get the expected result, but the Layer Tree does not update as shown here:


enter image description here


What am I missing, and how can I update the Layer tree from PyQGIS programmatically?



Answer



Tell the layer tree view to refresh your layer's symbology:


iface.layerTreeView().refreshLayerSymbology( iface.activeLayer().id() )

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...