QCombobox Enable and disable items based selection of item.
-
I have many QCombobox 's, I am adding items to all combobox 's in constructor. All items in QCombobox 's are common.
My requirement is:
If Item1 is selected in any combobox1 it shouldn't show in all other combobox's. if selection of item is changed combobox1, accordingly updated items in all other combobox's.@SGaist please guide me.Thanks in advance for your help.
-
@Mahi_1990 said in QCombobox Enable and disable items based selection of item.:
If Item1 is selected in any combobox1 it shouldn't show in all other combobox's. if selection of item is changed combobox1, accordingly updated items in all other combobox's
So you need to write code to implement just this. Use, say, void QComboBox::currentTextChanged(const QString &text) signal to which you attach a slot that goes removes the
text
parameter's value from all other comboboxes if that is what you want. Don't forget that you will (presumably) also want to re-add into other comboboxes whatever was previously selected and got removed but is now no longer selected. That might mean you need to keep a record of what all comboboxes start out with initially so that you can restore. Or if you use models for comboboxes' data you might have proxy models which filter out the undesired item in other combos. -
@JonB
Thanks for your time reply for me.
Yes you got it what i am looking for, I need to keep track of all combobox's. Basically, I need unique index from combobox(out of available index's). I prefer to some kind of model can you please point me to right model I should use to get my desired results please.Thanks,
Mahesh -
@Mahi_1990 said in QCombobox Enable and disable items based selection of item.:
Basically, I need unique index from combobox(out of available index's)
I don't know what this sentence means.
For a combobox just containing texts a QStringListModel should suffice.
If you are saying: you have multiple combos, all show the same items, whenever an item is selected in one of them it cannot be selected in any other (so the combos as a group allow selection of multiple items from the list but each must be unique no duplicates), or something similar. Then you might implement this by having a separate proxy model (with source model being the single shared model) on each one which excludes any of the items selected in any of the others. Otherwise I don't think you can disable or hide an item at the combobox level, so you would have to maintain separate string lists for each one and remove/restore as items get selected/deselected in other combos.
Unless I misunderstand what you want to achieve :)
-
@JonB
Thanks for your time.What I am trying to implement:
I have many systems in my hardware configuration, for each system I should provide channel selection using combobox. I can load items to combobox QStringListModel no problem here(In Image you see all items are manually, I have to upgrade this to load it from QStringListModel )
What I am looking for is if user selects channel 1 for xx system, for other systems channel 1 should not visible, but it should be there in the list, because I am using index as channel number in downstream logics. -
@Mahi_1990
And I have suggested the two ways you might do this:-
Either keep a separate model/list in each combobox so that you can remove and re-add items as they are selected/deselected in other combos; or
-
Impose a QAbstractProxyModel (will be a QIdentityProxyModel with a little configuration) on each combo sitting atop the
QStringList
model which excludes any item which has been selected in all combos other than itself.
-