[QGIS-Developer] How to turn on CustomLayerOrder (PyQGIS)

David Signer david at opengis.ch
Thu Oct 24 00:06:19 PDT 2024


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 at 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) 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 at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20241024/0117e0ef/attachment.htm>


More information about the QGIS-Developer mailing list