How can I get a QListWidget element by name?

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

For example, if I have the following QListWidget with 4 elements, how can I get an element that contains text = dan?

QListWidget

+6
source share
3 answers

Python is equivalent to Wahancho:

 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() 
+9
source

You can use the QListWidget::findItems() function. For instance:

 QList<QListWidgetItem *> items = listWidget->findItems("dan", Qt::MatchExactly); if (items.size() > 0) { // An item found } 
+5
source
 items = self.listWidgetName.findItems("dan",Qt.MatchContains); 

This works best when working with a QListWidget item

0
source

Source: https://habr.com/ru/post/971383/


All Articles