Reputation: 12775
I have a QT5 application with a QTableView
, i want to create an action with Go-To Cell functionality .
The problem i am facing is that according to the documentation Only selectRow
and selectColumn
methods are available as public slots .
In addition i have found a setSelection method which is [virtual protected]
, and there is a setSelectionModel but i cannot wrap my head around constructing the QItemSelectionModel
to select a single cell .
This seems a trivial feature , but for some reason it is not part of the QT api .
Upvotes: 3
Views: 3068
Reputation: 1667
To select one item use QItemSelectionModel::select
selectionModel()->select( index, QItemSelectionModel::ClearAndSelect );
Make sure that selection behavior set for single seleciton
setSelectionMode(QAbstractItemView::SingleSelection);
Upvotes: 3