PDA

View Full Version : QItemSelection::select on a Tree model



jeeie
13th March 2014, 17:23
Hi there,

I'm trying to programmatically select a number of rows in a QTreeView showing the contents of a custom QStandardItemModel.


QItemSelectionModel* selectionModel = myTreeView->selectionModel();
QItemSelection selectedItems;

selectedItems.select(topIndex, bottomIndex);
selectionModel->select(selectedItems, QItemSelectionModel::ClearAndSelect);


When the topIndex (May 01) and bottomIndex (May 02) rows have the same parent, it works well.


+ May
|-- 01 // selected
|-- 02 // selected


However, if the bottomIndex (May 02) doesn't have the same parent as the topIndex (April 30), no items are selected:


+ April
|-- ...
|-- 30
+ May
|-- 01
|-- 02


Is this a limitation of QItemSelection::select method? Or am I misusing it?
I was wondering if this should be done manually, by selecting individual ranges in each branch and merging them after.

Thank you for your answer!

Best,
j

wysota
20th March 2014, 18:35
If you want to select items with different parents, you have to merge separate selections. Even though your view shows May 1 after April 30, in the model there is no order relation between those two elements thus you cannot define a continous "range" covering both of them.