Hi,
I have an editable QComboBox, that I use to show a children list of a single leaf of a tree model.
Which means:
Qt Code:
myCoboBox->setModel(myTreeModel); myCoboBox->setRootIndex(index); //the index is the QModelIndex of a child item in the treeTo copy to clipboard, switch view to plain text mode
This works well, the combo box shows a list of children of the item who's index I set in the setRootIndex().
The problem I am having is with adding new items via the editable lineedit.
When I type in a new item which does not exist in the list the combo box is showing, and hit enter, the item gets added to the model - however, not as a child of the combo's root index as I expected, but as a child of the root index of the tree model.
I have connected a slot to the model's rowsInserted() and indeed the combo box adds the item with an invalid QModelIndex (which means the root index of the model).
My question is:
Since QComboBox does hold the notion of working with a specific level of an hierarchical model, my first thought is that I might have missed something in the way I am using it to add a new item.
I have read QComboBox's documentation and could not find anything I might have missed - but that does not mean I didn't.
I could add my own custom delegate to the combo box's line edit and there make sure that the insertion is done right, but if there is a "out of the box" way to do it which I missed, that would be better.
Thanks in advance!
Bookmarks