<div dir="ltr"><div>First you have to retrieve the current layertree to do modifications:<br></div><div>tree = QgsProject.instance().layerTreeRoot()<br></div><div>...and after setting your order:</div><div>tree.setCustomLayerOrder(layersII)<br></div><div>...you have to set that a layer order should be considered:</div><div>tree.setHasCustomLayerOrder(True)</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 23, 2024 at 6:33 PM coder via QGIS-Developer <<a href="mailto:qgis-developer@lists.osgeo.org">qgis-developer@lists.osgeo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div>
<div dir="auto" id="m_5175759324528832305compose-body-wrapper"><div dir="auto"><div dir="auto">Hello</div><div dir="auto">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:</div><div dir="auto">
QgsLayerTree().setCustomLayerOrder(layersII)</div><div dir="auto">but
nothing happens and</div><div dir="auto"> print
(QgsLayerTree().hasCustomLayerOrder()) </div><div dir="auto">returns
False. The API documentation
(<a href="https://qgis.org/pyqgis/master/core/QgsLayerTree.html" target="_blank">https://qgis.org/pyqgis/master/core/QgsLayerTree.html</a>) 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.
</div><div><br></div></div></div>
</div></div>_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
</blockquote></div>