colleagues! IDE QT Creator 5.10. I have this question. There is a QComboBox which has many items. Depending on the mode change, some items should become unselectable, but you cannot simply erase the current set of items and fill in only the allowed ones. It is necessary to make the unavailable items remain, but change the color to gray and become unavailable for the user to select. It is necessary that the numbers of allowed items of the drop-down menu do not change, because the choice of items and the change of modes can be performed not only by the user, but also by the controlled system, and its numbers are fixed. Example:
QStringList interlivingPSK; interlivingPSK << "1: Zero" << "2: Ultra Short" << "3: Very Short" << "4: Short" << "5: Medium" << "6: Long" << "7: Very Long"; ui->comboBoxInterleaverPSK->addItems(interlivingPSK); ui->comboBoxInterleaverPSK->setCurrentIndex(4);
How, for example, to "gray" points 2, 3, 5, 7?
Refer to the
QComboBox model and through it make the elements inactive:
QStandardItemModel* model = (QStandardItemModel*) ui->comboBoxInterleaverPSK->model(); model->item(1)->setEnabled(false); model->item(2)->setEnabled(false); model->item(4)->setEnabled(false); model->item(6)->setEnabled(false);