PDA

View Full Version : QTreeView multiselection



mentalmushroom
14th September 2011, 10:52
I am trying to implement automatic selection of the dragged rows in QTreeView (rows that were moved by a user must be selected after dropping). I use the following to achieve this:

selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
The problem is the further selection behavior: if I Shift+click some row it selects a range between the clicked row and the previous row of the first item selected. I found out this is somehow related to currentIndex of QTreeView. Setting currentIndex manually helps, but still it works only in 50% of cases: if you set current to the top row then it properly works when you try to shift+click the row below (but not above, because rows below will be deselected), or if you set current index to the bottom row it properly works when you shift+click the row above (but not below, because rows above become unselected). In brief, after dragging I want to select these only rows and allow further selection of rows via shift+click, so no rows lose their selection state. This is very similar to crtl+click behavior and ExtendedSelection mode, only I don't know how to make the same programmatically.