Return value from listWidget in pyqt4

Whenever I try to save a selected value from a list using

foo=self.listWidget.currentItem()

this is what i get as the value for foo:

<PyQt4.QtGui.QListWidgetItem object at 0x023BDD68>

This approach makes sense, but obviously not what I asked him about. I know how to select the actual item, but is there not one method for this, for example, for every other input widget?

+3
source share
1 answer

From PyQt4 QListWidgetItem docs you can use:

item = self.listWidget.currentItem()
value = item.text()

Or in one line:

value = self.listWidget.currentItem().text()
+4
source

All Articles