PDA

View Full Version : QTableView selection pattern



tuli
18th August 2014, 21:08
Hi,


Say i have a QTableWidget with a bunch of rows and columns. I i start selecting from the middle of a row and pull my mouse down, then it will only select one 'column' of items. However, i would like it to select ALL items between start and end of my selection.


i have illustrated this here (behold my paint skills):

https://i.imgur.com/9FBPr5I.png



I have tried to catch the selectionChanged() signal and remodel the selection there (ie, iterate all items, check if they are "within" the selection, and select them if they are). However, that is very, very slow and inefficient. Among other things the Qt will not recognice the "shape" of the selection and change it back automatically with every tiny mouse move.



what would be the best way to make that happen?

thanks.

wysota
19th August 2014, 13:21
Reimplement QAbstractItemView::setSelection() for your table.

tuli
19th August 2014, 15:36
but that has the same deficit: the tableview will not know about this new selection "shape", so it will fire selection changed events continuously, even if the selection hasnt actually changed...

wysota
19th August 2014, 15:47
but that has the same deficit: the tableview will not know about this new selection "shape", so it will fire selection changed events continuously, even if the selection hasnt actually changed...

How did you reimplement setSelection()? I just checked it and it works as expected.