QTableView select 单格
QTableView select single cell
我有一个带有 QTableView
的 QT5 应用程序,我想创建一个具有 Go-To Cell 功能的操作。
我面临的问题是,根据 documentation 只有 selectRow
和 selectColumn
方法可用作 public 插槽。
此外,我找到了一个 setSelection method which is [virtual protected]
, and there is a setSelectionModel,但我无法全神贯注地构建从 QItemSelectionModel
到 select 的单个单元格。
这似乎是一个微不足道的功能,但出于某种原因,它不是 QT 的一部分 api。
到select一项使用QItemSelectionModel::select
selectionModel()->select( index, QItemSelectionModel::ClearAndSelect );
确保select离子行为设置为单选
setSelectionMode(QAbstractItemView::SingleSelection);
我有一个带有 QTableView
的 QT5 应用程序,我想创建一个具有 Go-To Cell 功能的操作。
我面临的问题是,根据 documentation 只有 selectRow
和 selectColumn
方法可用作 public 插槽。
此外,我找到了一个 setSelection method which is [virtual protected]
, and there is a setSelectionModel,但我无法全神贯注地构建从 QItemSelectionModel
到 select 的单个单元格。
这似乎是一个微不足道的功能,但出于某种原因,它不是 QT 的一部分 api。
到select一项使用QItemSelectionModel::select
selectionModel()->select( index, QItemSelectionModel::ClearAndSelect );
确保select离子行为设置为单选
setSelectionMode(QAbstractItemView::SingleSelection);