I am trying move/position a layer to the bottom of the TOC by using addTopLevelItem on all other layers. I unsure how to reference the layers as QTreeWidgetItem's.
def bg_bottom_level_item(self):
layers = self.canvas.layers()
layerlist = []
for layer in layers:
layerID = str(layer.id())
if "Auto_Background" not in layerID:
layerlist.append(layer)
else:
pass
for layer in layerlist:
leg = qgis.utils.iface.mainWindow().findChild(QTreeWidget, 'theMapLegend')
item = QTreeWidgetItem(layer)
leg.addTopLevelItem(item)
Error:
QTreeWidgetItem(QTreeWidgetItem): argument 1 has unexpected type 'QgsRasterLayer'
Or does anyone have another solution for moving layers around in the TOC?