With PyQGIS 3, I defined a comboBox
to list layers from a QGIS project. I want to use the selected one to execute a treatment. I tried comboBox.currentData()
class but it doesn't seem to be the good way.
How can I handle the selected layer from the comboBox
as a vector layer ?
Maybe with comboBox.itemData()
or comboBox.currentIndex()
classes ?
# ComboBox
layers = QgsProject.instance().layerTreeRoot().children()
self.dlg.comboBox.addItems([layer.name() for layer in layers])
# Not the good way
selectedLayer = self.dlg.comboBox.currentData()
# Vector Layer
mySelectedLayer = QgsVectorLayer(selectedLayer, 'polygon', 'ogr')