[英]How can I get QListWidget item by name?
I have a QListWidget
which displays a list of names using PyQt in Python . 我有一个
QListWidget
,它在Python中使用PyQt显示名称列表。 How can I get the QListWidgetItem
for a given name? 如何获得给定名称的
QListWidgetItem
?
For example, if I have the following QListWidget
with 4 items, how can I get the item which contains text = dan? 例如,如果我有以下包含4个项目的
QListWidget
,如何获取包含text = dan的项目?
The python equivalent to vahancho's answer: 相当于vahancho答案的python:
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()
You can use QListWidget::findItems()
function. 您可以使用
QListWidget::findItems()
函数。 For example: 例如:
QList<QListWidgetItem *> items = listWidget->findItems("dan", Qt::MatchExactly);
if (items.size() > 0) {
// An item found
}
items = self.listWidgetName.findItems("dan",Qt.MatchContains);
这在使用QListWidget
项目时效果最好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.