Nominate our 2022 Qt Champions!

QComboBox - how to click on QStandardItem?

  • Hello,

    I try to create QComboBox with checkBoxes. Now I have QComboBox, and add to it QStandardItems.

    my code:

    void myComboBox::addItem(const QString &text)
        int row = model->rowCount();
        QStandardItem* item = new QStandardItem();
        item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
        item->setData(Qt::Unchecked, Qt::CheckStateRole);
        model->setItem(row, 0, item);


    When I click on red area everything is ok - I can checked and unchecked the item. But when I click on green area there is no effect.

    Goal: When I click on item in green area I would like to checked or unchecked his red area square and don't close comboBox ( because this is combobox with checkBoxes, so user maybe want to select more items ).

    I try QComboBox' s signals but there is no effect.

    I add:


    and signal


    Now I can click on green area and change his checked/unchecked square ( red area ). But the problem is when I clicked on any item I close QComboBox too…

    EDIT 2:
    I add to slot to signal QComboBox::activated


    This is good, but I see that qcombobox is close and next is open. So must be better solution

    EDIT 3:
    I find solution:

Log in to reply