can't select item in a QTreeWidget via code
I have a QCombox and in the combobo a TreeWidget
Code:
comboBox->setModel(treeWidget->model());
comboBox->setView(treeWidget);
Now I want to pre select an item in this treeWidget
Code:
treeWidget->scrollToItem (Item);
treeWidget->setCurrentItem(Item);
But for some reason, it doesn't select the Item.
In the combobox is still the first toplevelItem visible and when I click on the combobox he opens the correct toplevelitem, where Item is placed, but it's not selected.
Is it a bug, or am I on the wrong way?
Re: can't select item in a QTreeWidget via code
Instead of this:
Code:
treeWidget->scrollToItem (Item);
treeWidget->setCurrentItem(Item);
You should set correct index on your QComboBox:
Code:
comboBox->setCurrentIndex(treeWidget->indexOfTopLevelItem(Item));
Anyway, why do you want to put a QTreeWidget into a combo box? IMHO if you have a tree structure it won't be nice. And if you don't have a tree structure, what's the point of using QTreeWidget here?