Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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->setText(text);
        item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
        item->setData(Qt::Unchecked, Qt::CheckStateRole);
        model->setItem(row, 0, item);
        this->setModel(model);
    }
    

    tmp3.png

    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.

    EDIT:
    I add:

    item->setSelectable(true);
    

    and signal

    QComboBox::activated
    

    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

    myComboBox::showPopup();
    

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

    EDIT 3:
    I find solution:

    https://stackoverflow.com/questions/22813494/qcombobox-with-checkboxes


Log in to reply