QTableView - Limit number of selected items?
-
The question is in the title.
There is no function QTableView::set_Max_Number_SelectedItems( int ).When the number of selected items is 2, I want to disable selection of item.
Thanks
-
A couple of ways come to mind
-
Set the TableView to single selection mode, and create your Delegate. Inside the Delegate's paint event you can override how it gets painted by checking some data you have set for that index. For each selection you have your selectionChangedSlot called where you can keep track of which ones get selected and deselected setting the data for that index.
-
QTableView has a protected methods "emitSelectionChanged()". For which I imagine gets called before the selectionChanged signal does, so here you can make sure no more then two items are to be in the selection model (QItemSelectionModel) .
Sorry for all the hand waiving here, if I can explain it any more let me know and I will try
-
-
Hi,
What about implementing your own QItemSelectionModel ? You can reimplement the select slots and do nothing if the selection size is two.
Hope it helps
-
@DBoosalis, thanks for your answer.
The solution I choosed is described here.http://stackoverflow.com/questions/27272543/qtableview-limit-number-of-selected-items
Cheers all.