我有一个QSortFilterProxyModel,我需要选择要删除的行,所以我使用了一个QPersistentModelIndex。QPersistentModelIndex可以很好地处理多行选择,而其他方法不能删除所有行。我的问题是,我不能用它需要QModelIndex的QPersistentModelIndex来mapToSource。我该如何克服这个问题呢?
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)发布于 2020-07-21 00:16:37
如果你想把QPersistentModelIndex转换成QModelIndex,你只需要使用:
for p_index in index_list:
index = QModelIndex(p_index)
ix = table_view.model().mapToSource(index) https://stackoverflow.com/questions/62999366
复制相似问题