How do I remove an item from a QListView
? For QComboBox
it's removeItem
but I can'开发者_如何转开发t find an equivalent function for QListView
.
Using pyqt4.
In QListWidget you can remove directly with takeAt()
, but not in QListView (read Qt Model/View). You should use the widget unless you need your own model. If QListView is what you want then get model, and remove, i.e. qListView.model().removeRow(row)
You should use a model model = QStandardItemModel()
. Then, this model should be assigned to QListView listView.setModel(model)
. So, you could directly work in the model model.removeRow(row)
for removing, standardItem = model.item(row)
for getting the value, model.insertRow(0, standardItem)
for inserting into the first position. You can also see additional functions to work with models in QStandardItemModel Class
You should use model, not view.
see https://doc.qt.io/qt-4.8/qabstractitemmodel.html#removeRow
精彩评论