Allow selection of only single item in QItemSelectionModel
-
I have a TableView which uses an ItemSelectionModel for selection of rows. While it is working (I can select rows), I want to limit my selection to a single row only. In other words, if a row is already selected, deselect the old one and select only the new one. Using shift/ctl should not allow more than a single row to be selected.
Although I am using ItemSelectionModel in QML, this seems to be just a wrapper for QItemSelectionModel (and this forum seems to get more answers than QML forum). Can someone advise on the combination of selection flags I need to use? (I've tried a bunch of combinations and can't find one that does what I want).
I have read the selection flag documentation but I'm no further ahead (in fact its a bit confusing).
If I call select with options "Current" | "Toggle" then I will limit selection to a single row; however, it does not allow me to DESELECT that row by clicking on it again. (i.e. not toggling)
-
Edit: Seems these options are available for the Widgets QTableView but there doesn't seem to be corresponding options in QML.
I think you want to set the
SelectionBehavior
toQAbstractItemView::SelectRows
and theSelectionMode
toQAbstractItemView::SingleSelection
.