PDA

View Full Version : QComboBox with a tree model - adding items problem.



high_flyer
15th January 2017, 22:15
Hi,

I have an editable QComboBox, that I use to show a children list of a single leaf of a tree model.
Which means:


myCoboBox->setModel(myTreeModel);
myCoboBox->setRootIndex(index); //the index is the QModelIndex of a child item in the tree


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!

anda_skoa
16th January 2017, 08:54
That sounds like a bug to me.

Cheers,
_

high_flyer
23rd January 2017, 14:28
I have submited the bug, and a patch, in case someone stumbles on this.
https://bugreports.qt.io/browse/QTBUG-58313

anda_skoa
24th January 2017, 09:20
I don't think the Qt project an accept patches that do not go through Gerrit, mostly for legal reasons.

Anyway, good find!

Cheers,
_

high_flyer
24th January 2017, 10:33
I know - the patch is there to help the assigned developer.
I didn't have the time to commit to gerrit my self yet, need to bring my repo up to date and to configuring it for gerrit, run tests etc.
Will see what comes earlier, me committing to gerrit, or them using my submission ;-)