Combobox in Qtableview
-
Have another loop/iterator through all the items which are in the combo box and remove any which are not in the guess list now
I tired this but not working correctly.. now if item in guesslist then also it got removed ???
QStringList itemsInComboBox; for (int index = 0; index < guesslist.count(); ++index) { //check in list for (int item = 0; item < combo->count(); ++item) { //check in combobox itemsInComboBox << combo->itemText(item); qDebug() << "before remove " << itemsInComboBox; if ( guesslist[index] != itemsInComboBox[item] ) combo->removeItem(item); } }
Hi,
adding those that appear in guesslist code-for (int i = 0; i < guesslist.count(); i++) { if (combo->findText(guesslist[i]) != -1)//-1 means "not found" { continue; } else { combo->addItem(guesslist[i]); //Add to QCombobox }
///remove which are not in the guess list code below I tried multiple times but this is not working correctly ? I don't want to change my selection when any item added / removed / replaced ..Plz help😞
QStringList itemsInComboBox; for (int index = 0; index < guesslist.count(); ++index) { //check in list for (int item = 0; item < combo->count(); ++item) { //check in combobox itemsInComboBox << combo->itemText(item); qDebug() << "before remove " << itemsInComboBox; if ( guesslist[index] != itemsInComboBox[item] ) combo->removeItem(item); } }
Thanks in advance
-
-
Have another loop/iterator through all the items which are in the combo box and remove any which are not in the guess list now
for me this way is not working any how selection of combobox is going away..
how can i store the selection of combobox ?@n-2204 https://doc.qt.io/qt-5/qcombobox.html#currentIndex-prop or currentText() if you can't relay on the order of the items or itemData() if you use roles, later on you can find the same text with different index, if that's the case, using findText() or findData().
Do you read any documentation at all? It's all there in clear text.
-
Have another loop/iterator through all the items which are in the combo box and remove any which are not in the guess list now
for me this way is not working any how selection of combobox is going away..
how can i store the selection of combobox ? -
@n-2204
The whole thing, for what I think you say you want:QString selected = combo->currentText(); combo->clear(); combo->addItems(guesslist); combo->setCurrentText(selected);
@JonB said in Combobox in Qtableview:
The whole thing, for what I think you say you want:
QString selected = combo->currentText();
combo->clear();
combo->addItems(guesslist);
combo->setCurrentText(selected);
edited
thanks it works,, there some other mistake in code -
@n-2204 https://doc.qt.io/qt-5/qcombobox.html#currentIndex-prop or currentText() if you can't relay on the order of the items or itemData() if you use roles, later on you can find the same text with different index, if that's the case, using findText() or findData().
Do you read any documentation at all? It's all there in clear text.
@artwaw said in Combobox in Qtableview:
currentText() if you can't relay on the order of the items or itemData() if you use roles, later on you can find the same text with different index, if that's the case, using findText() or findData().Do you read any documentation at all? It's all there in clear text.
Thanks,,i trying to implement but thing is removeitem+selection from combobox not working correctly
-
@artwaw said in Combobox in Qtableview:
currentText() if you can't relay on the order of the items or itemData() if you use roles, later on you can find the same text with different index, if that's the case, using findText() or findData().Do you read any documentation at all? It's all there in clear text.
Thanks,,i trying to implement but thing is removeitem+selection from combobox not working correctly
@n-2204 said in Combobox in Qtableview:
currentText() if you can't relay on the order of the items or itemData() if you use roles, later on you can find the same text with different index, if that's the case, using findText() or findData().
From my code all you need to restore the selection is the
combo->setCurrentText(selected);
.