Colleagues! IDE QT Creator 5.10. I have this question. There is a QComboBox, which has a lot of points. Depending on the change of modes, some items should become unavailable for selection, but you can’t just erase the current set of items and fill in only allowed ones. It is necessary to make the inaccessible items remain, but change color to gray and become inaccessible for selection by the user. It is necessary that the numbers of allowed items in the drop-down menu do not change because the choice of items and mode change can be performed not only by the user, but also by the managed system, and her 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, "zagreit" paragraphs 2, 3, 5, 7?

    1 answer 1

    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); 
    • Thanks It works! But why lie with a capital letter? - Victor
    • @Victor, clicking on the tick (by accepting the answer) you express gratitude, and that the answer solved your problems - AR Hovsepyan
    • @ Victor, rewrote the code from the code on the python and did not notice False :) - gil9red