开发者

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 way of doing this? Something closer to lw.removeItem(name)?


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜