[QGIS-Developer] repaint layertree/legend

Richard Duivenvoorde rdmailings at duif.net
Mon Oct 19 03:37:27 PDT 2020


Hi Devs,

I'm puzzled on how to force the LayerManger/Layertree to repaint itself (or parts).

Context: I'm trying to configure a layer via PyQGIS to be 'temporal enabled'. 
All goes well but the little 'Temporal'-indicator does not show up.

Using this to actually enable the layer:

l=iface.mapCanvas().currentLayer()
p=l.temporalProperties()
p.setMode(QgsVectorLayerTemporalProperties.ModeFeatureDateTimeInstantFromField)
p.setStartField('Time')
p.setDurationUnits(QgsUnitTypes.TemporalUnit.TemporalSeconds)
p.setFixedDuration(3600)
p.setIsActive(True) # OK

BUT: the little 'indicator' does not show up. I've tried to throw up some signals

#p.changed.emit() # does not update the Layer Panel
#v=iface.layerTreeView()
#v.update() # not working
#v.repaint() # noep
#v.currentLayerChanged.emit(l) # nothing
#QCoreApplication.processEvents() # nope nor working either

I have tried to get the actual indicator:
n=QgsProject.instance().layerTreeRoot().findLayer(l) # find QgsLayerTreeLayer
i=iface.layerTreeView().indicators(n)

but no repaint untill I actually click in the Layers panel..

So Question: is there some magic to let this TreeView (which it actually is) to repaint itself?

Which reminds me on an issue I had earlier: IF you change the filter of a layer (via PyQGIS) and that layer had a layer count, then the (visible) count was also not updated untill you clicked the legend.

I'm puzzled to what level I should repaint the widget: full of only one node or...

Any input appreciated.

Regards,

Richard Duivenvoorde


More information about the QGIS-Developer mailing list