qgis-sample-QgsSublayersDialog.py
from qgis.core import (QgsLayerTreeLayer, QgsMapLayerRegistry,
QgsProject, QgsVectorLayer)
from qgis.gui import QgsSublayersDialog
sublayers_dialog = QgsSublayersDialog(QgsSublayersDialog.Ogr, 'Title')
root = QgsProject.instance().layerTreeRoot()
layers = []
for child in root.children():
if isinstance(child, QgsLayerTreeLayer):
layer = QgsMapLayerRegistry.instance().mapLayer(child.layerId())
if isinstance(layer, QgsVectorLayer):
print("- layer: " + child.layerName() + " ID: " + child.layerId())
layers.append(
'%s|%s|%s|%s' % (layer.id(), layer.name(),
layer.featureCount(), layer.geometryType())
)
sublayers_dialog.populateLayerTable(layers, delim="|")
sublayers_dialog.show()
sublayers_dialog.selectionNames()
sublayers_dialog.selectionIndexes()