
Originally Posted by
alisami
my problem is that, in the designer, i cannot set an object name for te treewidgetitem's and the only way i have seen is to compare the treewidgetitem's name when the message type is selected and open the dialog box.
is there any other way to identify the items selected in the treewidget ?
Each item has an index associated with it, namely a row number, column number and the index of a parent. For instance message type 13 would have an index of "row 2, parent with row 0" or in code:
int row = index.row();
int parentrow = index.parent().row();
if(index.parent().isValid()){
switch(parentrow){
case 0: if(row==0) handle_type_11(); else if(row==1) handle_type_12(); else ...
...
}
} else {
// group clicked
switch(row){
case 0: handle_group_1(); break;
case 1: handle_group_2(); break;
//...
}
}
QModelIndex index = tree->currentIndex();
int row = index.row();
int parentrow = index.parent().row();
if(index.parent().isValid()){
switch(parentrow){
case 0: if(row==0) handle_type_11(); else if(row==1) handle_type_12(); else ...
...
}
} else {
// group clicked
switch(row){
case 0: handle_group_1(); break;
case 1: handle_group_2(); break;
//...
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks