[QGIS-Developer] How to turn on CustomLayerOrder (PyQGIS)
coder
coder at odyhpc.com
Thu Oct 24 08:03:58 PDT 2024
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 at lists.osgeo.org <mailto: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 <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 <mailto:QGIS-Developer at 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>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20241024/731ce62c/attachment.htm>
More information about the QGIS-Developer
mailing list