Use of several QCombobox that work together
-
Im trying to use several comboboxes who are linked together.
I have 5 sensors and each one have a own address.
It looks like that:
On the right are 5 combo boxes with selectable items: N.C. (not connected),1,2,3,4 and 5.
e.g. If Line 1 is set to 1, the item 1 should be removed from line 2-5
Picture:
So if on line 1 selected 1 and on line 3 selected 2. On line 5 eg. there should only be N.C.,3,4 and 5. So no double choice.
I just tried it like that, but it dont dependent on the other comboboxes.:
for(int i = 1 ; i <= Initialisationlist.count() ; i++) { QLabel * label = this->findChild<QLabel *>("label_"+QString::number(i)); QComboBox * CBox = this->findChild<QComboBox*>("CBoxSensor_"+QString::number(i)); if(label) { CBox->clear(); CBox->addItem("N.C."); label->setText(Initialisationlist.at(i-1)); for (int x=1 ; x <= Initialisationlist.count(); x++) { CBox->addItem(QString::number(x)); } CBox->setCurrentIndex(0); } }
-
Hi,
One possible way to do that is to use a common model that contains all the data and then use a QFilterProxyModel for each QComboBox where you filter out the already selected values.
The other solution is to regenerate the content of all the combo boxes based on the value that just changed and all the non NC.
-
Hi,
One possible way to do that is to use a common model that contains all the data and then use a QFilterProxyModel for each QComboBox where you filter out the already selected values.
The other solution is to regenerate the content of all the combo boxes based on the value that just changed and all the non NC.
@SGaist whats does a common model mean? And how could i use it?
And use one common model for all combo boxes Informations and then use QFilterProxyModel for each filter for the boxes -
Do you know what a model is ?
Did you check the QSortFilterProxyModel documentation ? -
Do you know what a model is ?
Did you check the QSortFilterProxyModel documentation ?@SGaist im soo sorry to be such a noob:D
I really dont know what a model or even a common model is. What i have to read about? Do you mean QAbstractItemModel or what i have to read about? -
@SGaist whats does a common model mean? And how could i use it?
And use one common model for all combo boxes Informations and then use QFilterProxyModel for each filter for the boxes@AlexKrammer as @SGaist suggested, you may want to provide a custom model for your QComboBox objects.
-
@AlexKrammer as @SGaist suggested, you may want to provide a custom model for your QComboBox objects.
@Pablo-J-Rogina
I understand. But one last question.
Every time when i change one combobox i have to reload all other comboboxes with their items? -
It's going to depend on the solution you choose.