I want to set rendering order for my layer Layer name
by time
field in descending order. When the layer is loaded in the project, I run the code below in the console and it works fine. But when I put it in my plugin code, it doesn't set the rendering order, it does just nothing. I tried to put it inside both processAlgorithm() and postProcessAlgorithm() with no outcome. What do I do wrong?
My QGIS version is 3.34.11-Prizren
layer = QgsProject.instance().mapLayersByName("Layer name")[0]
renderer = layer.renderer()
from qgis.core import QgsFeatureRequest
orderByClause = QgsFeatureRequest.OrderByClause('time', ascending=False)
orderBy = QgsFeatureRequest.OrderBy([orderByClause])
renderer.setOrderBy(orderBy)
renderer.setOrderByEnabled(True)
layer.triggerRepaint()