开发者

qt: remove item from QListView

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜