From what I know the combobox doesn't work well with hierarchical models. You can use setRootModelIndex() but then you won't see the indexes higher in the hierarchy.
From what I know the combobox doesn't work well with hierarchical models. You can use setRootModelIndex() but then you won't see the indexes higher in the hierarchy.
I have been digging for this for a while and just figured out a solution. Just going to put it here in case anyone ever needs something similar. The approach is to set the root model index to the parent of the element you want, set the current index to the element index within the element's siblings, and then to set the root model index back to the invisiblerootitem of the tree. For my code, it was something like this (loDeviceTree was the QTreeWidget, and loDeviceComboBox was the comboBox that contained loDeviceTree as its model/view):
loDeviceTree->setCurrentItem(DeviceIWant->parent(),0);
loDeviceComboBox->setRootModelIndex(loDeviceTree->currentIndex());
loDeviceComboBox->setCurrentIndex(IndexOfTheDeviceIWant)
loDeviceTree->setCurrentItem(loDeviceTree->invisibleRootItem(),0);
loDeviceComboBox->setRootModelIndex(loDeviceTree->currentIndex());
Bookmarks