Reputation: 1188
How can I remove an item with text "something" from a QStandardItemModel
that filled with QStandardItem
items and shown in a QListView
in pyqt
.
I made my QStandardItemModel
like code shown below:
item = QtGui.QStandardItem("something")
QStandardItemModel.appendRow(item)
Upvotes: 4
Views: 3494
Reputation: 1185
I believe the solution given only works when findItems returns a single item. Otherwise the first call to removeRow will invalidate the next items...
Upvotes: 0
Reputation: 120578
You will first need to find the items with the matching text, and then remove them from the model:
model = listview.model()
for item in model.findItems('something'):
model.removeRow(item.row())
Upvotes: 4