Issue
I have a QSortFilterProxyModel
, I need to select row for delete, so I am using a QPersistentModelIndex
. QPersistentModelIndex
is working well with multiple row selection, while other methods are not deleting all rows. My problem is, I can't mapToSource with the QPersistentModelIndex
it needs QModelIndex
. How can I overcome this?
model = QStandardItemModel()
filter = QSortFilterProxyModel()
self.filter.setSourceModel(model)
# Set the model/check function
table_view = QTableView()
table_view.setModel(filter)
# Delete Row using
index_list = []
for model_index in table_view.selectionModel().selectedRows():
index = QPersistentModelIndex(model_index)
index_list.append(index)
if index_list:
for index in index_list:
"The error is here, it only accepts `QModelIndex` and refuses `QPersistentModelIndex`"
ix = table_view.model().mapToSource(index.row())
# ix = table_view.model().mapToSource(index)
item = model.itemFromIndex(ix)
Solution
If you want to convert QPersistentModelIndex to QModelIndex you just have to use:
for p_index in index_list:
index = QModelIndex(p_index)
ix = table_view.model().mapToSource(index)
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.