Skip to content Skip to sidebar Skip to footer

Pyqt4: Less Round-about Way Of Removing Item From Qlistwidget?

I want to remove an item whose name I know. I came up with: item = lw.findItems(name, QtCore.Qt.MatchExactly)[0] lw.takeItem(lw.indexFromItem(item).row()) Is there any more direct

Solution 1:

This leaves a bit of ambiguity for multiple entries with the same text. I would lean more toward something like

[ lw.takeItem( i ) for i in range( lw.count ) if lw.item( i ).text() == name ]

This will remove all items matching name from the list. If you only want to remove the first instance, you need to expand this into a full for-loop that breaks at the first match.

Good luck!


Post a Comment for "Pyqt4: Less Round-about Way Of Removing Item From Qlistwidget?"