How can I get QListWidget item by name?

panofish picture panofish · Jun 26, 2014 · Viewed 14.2k times · Source

I have a QListWidget which displays a list of names using PyQt in Python. How can I get the QListWidgetItem for a given name?

For example, if I have the following QListWidget with 4 items, how can I get the item which contains text = dan?

QListWidget

Answer

panofish picture panofish · Jun 26, 2014

The python equivalent to vahancho's answer:

items = self.listWidgetName.findItems("dan",Qt.MatchExactly)

if len(items) > 0:

    for item in items:
        print "row number of found item =",self.listWidgetName.row(item)
        print "text of found item =",item.text()