Related to the following question but looking for a PyQGIS method:
QGIS Layer Order Panel - add layers at top of layer order
The following is a simple setup containing a group with three layers.
The code I use adds a new layer at the end of this group:
root = QgsProject.instance().layerTreeRoot()
group = root.findGroup('Main group')
vlayer = QgsVectorLayer('LineString?crs=epsg:27700', 'vlayer', 'memory')
QgsMapLayerRegistry.instance().addMapLayer(vlayer, False)
group.insertChildNode(-1, QgsLayerTreeLayer(vlayer))
In the Layer Order Panel, the newly added layer is at the end.
Is it possible to move this to the top without moving the layer in the Layers Panel?