I'm a little bit confused (I'm a newbie) on how to get a list of just the selected Items of a QListWidget (in a QGIS plugin).
I set up the manageGui function in this way:
def manageGui(self): selectedLayers = [] # Trying to set up the listWidgetView self.listWidget.setEditTriggers(QtGui.QAbstractItemView.DoubleClicked|QtGui.QAbstractItemView.EditKeyPressed) self.listWidget.setSelectionMode(QtGui.QAbstractItemView.MultiSelection) self.listWidget.setViewMode(QtGui.QListView.ListMode) # Load the layers in the listWidget layers = [] for i in QgsMapLayerRegistry.instance().mapLayers().values(): #load only POLYGON layers, to filer out useless layers if i.geometryType() == QGis.Polygon: self.layers.append(i.name()) # Populate the listWidget with all the polygon layer present in the TOC self.listWidget.addItems(self.layers) #put the selected layers in a list selectedLayers = self.listWidget.selectedItems()but the listWidget.selectedItems() seems empty. If I print selectedLayers I just get [].
I also tried to run a loop over the listWidget:
#popultate the list with only the selected layers of the list for item in self.listWidget.selectedItems(): self.selectedLayers.append(item)but it doesn't work neither, always and empty list.
Thanks!
أكثر...
I set up the manageGui function in this way:
def manageGui(self): selectedLayers = [] # Trying to set up the listWidgetView self.listWidget.setEditTriggers(QtGui.QAbstractItemView.DoubleClicked|QtGui.QAbstractItemView.EditKeyPressed) self.listWidget.setSelectionMode(QtGui.QAbstractItemView.MultiSelection) self.listWidget.setViewMode(QtGui.QListView.ListMode) # Load the layers in the listWidget layers = [] for i in QgsMapLayerRegistry.instance().mapLayers().values(): #load only POLYGON layers, to filer out useless layers if i.geometryType() == QGis.Polygon: self.layers.append(i.name()) # Populate the listWidget with all the polygon layer present in the TOC self.listWidget.addItems(self.layers) #put the selected layers in a list selectedLayers = self.listWidget.selectedItems()but the listWidget.selectedItems() seems empty. If I print selectedLayers I just get [].
I also tried to run a loop over the listWidget:
#popultate the list with only the selected layers of the list for item in self.listWidget.selectedItems(): self.selectedLayers.append(item)but it doesn't work neither, always and empty list.
Thanks!
أكثر...