In PyQt I can have QListWidget select an item programmatically using QListWidget.setCurrentItem(item)
. And this, of course, will select an item for me inside my QListWidget.
However, I'm wondering if there exists a method like setCurrentItems([item1, item2, item3])
where if I give a list, it will select all the items in QListWidget that match those items.
Right now my current implementation only allows me to select one item. In this case, the item 'data2'
index = ['data', 'data1', 'data2']
for i in index:
matching_items = listWidget.findItems(i, QtCore.Qt.MatchExactly)
for item in matching_items:
listWidget.setCurrentItem(item)
It would be cool if something like this could be done.
index = ['data', 'data1', 'data2']
for i in index:
matching_items.append(listWidget.findItems(i, QtCore.Qt.MatchExactly))
listWidget.setCurrentItems(matching_items)
obj
? – Eyeshot