Important: Please read the Qt Code of Conduct -

Disable or hide elements in comboBox

  • Hi,

    I have a comboBox with a model (QStringList)

    From C++ side :

    comboModel << "toto" << "gogo" << "jojo" << "coco" << "zozo" << "dodo";

    In QML side, I just want display all the item but two (coco and zozo) in a comboBox in keeping the real index.

    Like that :
    toto (idx 0)
    gogo (idx 1)
    jojo (idx 2)
    dodo (idx 5)

    Is it possible ?

    Thank you

  • Hi!

    Is it possible ?

    I don't think so.

  • Hi Wieland,

    Thank you for your answer.
    Should I do a model from QAbstractListModel and enumerate all elements? (role text and value/index) or it is better to insert an enum?

    Thank you

  • @RomanoFX Well, you can have a nice solution which will involve a little more effort or you can make it quick and dirty (maybe with some Javascript inside QtQuick). What are actually doing here? What's the purpose of the model and what are the indices needed for?

  • @Wieland Thank you for your answer. I really don't want doing it quickly and dirty :)

    An instrument got a configuration (binary file) and an array defines the kind of channel type (voltage, current, etc..) as an enum.
    So we take the enum, save it, and display the corresponding text with a QStringList.

    the enum : Voltage, current, pwm, thermocouple, counter
    BUT, some channels only do voltage , current and thermocouple. That's why I would keep the index of that enumerate.

    Please tell me if I am not clear.
    Thank you

  • I will do the first solution.

Log in to reply