Can I control enabled-ness of QComboBox from a QAbstractItemModel?
-
I have a class derived from QAbstractItemModel that is hooked up to a QComboBox. Is there a way to control the enabled-ness (setEnabled()) of the QComboBox from the model? My desire is that when there is only one item in the model, I want the QComboBox disabled, and if there is more than one item in the model, I want the QComboBox enabled.
If I return Qt::ItemIsSelectable from flags(), the combobox is drawn with no selection (even though I have selected the one-and-only item) which is not what I want - I want the selected item to be drawn, but the combobox disabled (which is what I get if I call setEnabled() directly on the combobox).
I can of course call setEnabled() from my code, bypassing the model, but I was hoping to find a way to do this that was more elegant.
Thanks,
Chris -
Hi,
You could emit a custom signal from your model and emit it when you've reach the point of change (only one item, and more that one). Then connect that signal to QComboBox setEnabled
Hope it helps