选择模型在使用 QSortFilterProxyModel 时得到错误的索引
selection model getting wrong index when working with QSortFilterProxyModel
我有 QStandardItemModel 和自己的 QSortFilterProxyModel 来过滤 QTableView 中的隐藏条目。当我 select 从下面的这个视图进入时,信号从 selection 模型发出。
view_table->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)
假设我在列表中有 5 个条目,条目号为 5。 4是隐藏的。当我 select 条目号。上面的 5 信号给我当前索引作为条目号。 4 个隐藏物品。
当项目隐藏在列表中时,我如何select更正索引(应该是 5)?
我想你要找的是QSortFilterProxyModel::mapToSource
。它采用代理的索引和 returns 来自源模型的相应索引。
QModelIndex proxyIndex = <whatever>
QModelIndex sourceIndex = myProxyModel.mapToSource(proxyIndex);
我有 QStandardItemModel 和自己的 QSortFilterProxyModel 来过滤 QTableView 中的隐藏条目。当我 select 从下面的这个视图进入时,信号从 selection 模型发出。
view_table->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)
假设我在列表中有 5 个条目,条目号为 5。 4是隐藏的。当我 select 条目号。上面的 5 信号给我当前索引作为条目号。 4 个隐藏物品。
当项目隐藏在列表中时,我如何select更正索引(应该是 5)?
我想你要找的是QSortFilterProxyModel::mapToSource
。它采用代理的索引和 returns 来自源模型的相应索引。
QModelIndex proxyIndex = <whatever>
QModelIndex sourceIndex = myProxyModel.mapToSource(proxyIndex);