Multiple QComboBoxes, I want to change the selection of a combobox based on the selection of another
I am brand new to QT. Learning on the fly.
I am designing a configuration wizard and have run into a dilema.
I have 8 QComboBoxes that contain the same list of selections from a model (subclassed QAbstractListModel).
The combo boxes are used to select devices attached to com ports.
If the user selects one item, I need to make sure that any other combo box that has that same selection changes to index 0 (a blank selection as defined in the model). This would seem to be more user friendly than requiring the user to first go back and de-select a previous selection, then come back and make the current selection.
Basically, there can be no repeated selections across the 8 combo boxes.
Currently, the only relationship between these 8 combo boxes are that they are common to a single QHBoxLayout.
Just off the top of my head...
You could create a helper class that knows about all of the combo boxes (perhaps keeps a list of pointers to them) and connect each of their currentIndexChanged signals to it. It could then iterate over all of the other boxes and clear any that match the same value.
I was in the "Can't see the forest for the trees" loop.
I was also focused on finding some magical way to do this through the model that holds the values used in the combo boxes.
In looking at this problem again. I think I am going to have to rethink my layout.
Currently, these comboboxes are not contained in a grid or table, they are just created in a layout.
In order to be able to know which combobox sent the signal, I am going to have to lay these combo boxes out in a grid or table widget, and use the signalMapper. That way I can get the row/col of who sent it, get the index or QString of that combobox, and check the others for their settings.
Does this sound correct? Or am I missing something again?
Using a layout or grid or table widget is independent of using a QSignalMapper. How you generate an id is up to you. You could just as easily manually number your QComboBoxes as (0..n)