PDA

View Full Version : [QT4] Selected row in a QTreeWidget



vfernandez
6th March 2006, 22:36
I'm using a QTreeWidget to display a list with two columns, so I only insert toplevel items on it. I only allow the user to select one row. Is there a way to know which row is actually selected? I mean the row number, not the QTreeWidgetItem. Thx.

wysota
6th March 2006, 23:48
Maybe something like this?

int MyTree::currentRow(){
QTreeWidgetItem *item = currentItem();
int ind = 0;
while((QTreeWidgetItem *wi = child(ind))!=0){
if(item==wi) return ind;
ind++;
}
return -1;
}

Mad Max
7th March 2006, 05:52
I think you need to use this method:

int pos = treeWidget->indexOfTopLevelItem ( treeWidget->currentItem())

prakash
9th March 2006, 12:54
May be it can help a bit.

_pKeywordSummeryTree->selectionModel()->select(_pKeywordSummeryTree->model()->index(_pKeywordSummeryTree:D ->indexOfTopLevelItem(item),0),QItemSelectionModel:: Select);