I am new to PyQt4 and especially the QListWidget. I am trying to get a (Python) list of of all labels currently displayed in the QListWidget. I'm able to to get a list of all the QListWidgetItems, but I'm not sure how to get to the labels from there...
This is what I use to get the list of all the QListWidgetItems:
items = []
for index in xrange(self.ui.QListWidget.count()):
items.append(self.ui.QListWidgetitem(index))
Thanks for your help!
.text()
returns the text within a QListWidgetItem. Note that you need to call .item(index)
on the original QListWidget instance to get the items contained in the list widget:
items = []
for index in xrange(self.ui.QListWidget.count()):
items.append(self.ui.QListWidget.item(index))
labels = [i.text() for i in items]