I am using Qt Designer 4.8.5 to develop a plugin (with QGIS 2.14.3-Essen).
I recently started to use QgsMapLayerComboBox
widgets instead of the conventional Combo Box
widget. However, I want to filter out a number of layers so that only a few are shown.
When I used the Combo box
widget, here is the code:
root = QgsProject.instance().layerTreeRoot()
main_group = root.findGroup('Main group')
layers = []
for group in main_group.children():
for layer in group.children():
layers.append(layer.layerName())
self.dockwidget.combo_box.clear()
self.dockwidget.combo_box.addItems(sorted(layers))
How can I translate the above code to work with QgsMapLayerComboBox
? I have seen the QgsMapLayerComboBox.setExceptedLayerList() but not exactly sure how to create such a list.