Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove item by text from QStandardItemModel in QT

Tags:

qt

pyqt

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)
like image 845
alizx Avatar asked Oct 28 '25 12:10

alizx


1 Answers

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())
like image 189
ekhumoro Avatar answered Oct 30 '25 13:10

ekhumoro