Hi David,
It's finally working! Thank you (and sorry for the delay in getting back to 
you).
AF
David Signer wrote:
First you have to retrieve the current layertree to do modifications:
tree = QgsProject.instance().layerTreeRoot()
...and after setting your order:
tree.setCustomLayerOrder(layersII)
...you have to set that a layer order should be considered:
tree.setHasCustomLayerOrder(True)
On Wed, Oct 23, 2024 at 6:33 PM coder via QGIS-Developer 
<qgis-developer@lists.osgeo.org <mailto:qgis-developer@lists.osgeo.org> > wrote:
Hello
I'm trying to change the rendering order for the layers in the canvas with the 
aid of QgsLayerTree. The code grabs each layer, checks whether is a QgsMapLayer 
instance, and generates a reordered list (layersII). Then, the code executes:
QgsLayerTree().setCustomLayerOrder(layersII)
but nothing happens and
print (QgsLayerTree().hasCustomLayerOrder())
returns False. The API documentation 
(https://qgis.org/pyqgis/master/core/QgsLayerTree.html 
<https://qgis.org/pyqgis/master/core/QgsLayerTree.html> ) indicates that 
customLayerOrder will only be used when hasCustomLayerOrder is True. I'm 
missing something here but after browsing and googling, I just haven't figured 
out how to make the change in rendering order active. Thanks.
_______________________________________________
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org <mailto:QGIS-Developer@lists.osgeo.org>
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer 
<https://lists.osgeo.org/mailman/listinfo/qgis-developer>
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer 
<https://lists.osgeo.org/mailman/listinfo/qgis-developer>
_______________________________________________
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to