PDA

View Full Version : QTableView & item grouping with another QTableWidget[solved]



ttvo
22nd April 2010, 14:18
Hi all,

I have a QTableView with a custom model that display
Table 1
Name Type
a Type1
b Type2
c Type3
d Type3
e Type3
now I have a need for item grouping, for example:
Table 2
Group Items Count
Group 1 a, b 2
Group 2 c, d, e 3

next, I need
1) the ability to highlight items in Table 1 when a row in Table 2 is selected. If "Group 1" is selected, then item # a and # b of Table 1 are selected/highlighted. I have a callback when a row in Table 2 is clicked as


QItemSelection selection;
QItemSelectionModel * selectionModel= m_ui->table1View->selectionModel();
...
// looping through QModelIndex that are stored
selection.select(modelIndex, modelIndex);
// end of looping
...
selectionModel->select(selection, QItemSelectionModel::SelectCurrent);
...
m_ui->table1View->setSelectionModel(selectionModel);
m_ui->table1View->setFocus();

but nothing is selected in Table1
2) I will also need the reverse, highlight of corresponding group when an item in table 1 is selected
Please help. Thanks in advance

----------
i only stored the QModelIndexes for the first column only because I have select row policy on my table. In the selection.select(...) line above, I had to look up for the last QModelIndex on that row via modelIndex.sibling call and that solves my problem