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?
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()
See documentation here:
https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QListWidget.html#PySide6.QtWidgets.QListWidget.findItems
5
You can use QListWidget::findItems()
function. For example:
QList<QListWidgetItem *> items = listWidget->findItems("dan", Qt::MatchExactly);
if (items.size() > 0) {
// An item found
}
5
items = self.listWidgetName.findItems("dan",Qt.MatchContains);
This works best while working with QListWidget
item