S
S
Svyatoslav Nemato2019-01-29 16:33:13
Qt
Svyatoslav Nemato, 2019-01-29 16:33:13

Qt checkbox this combobox?

I want to make a drop-down list with a CheckBox, so that when a ChexkBox is selected, it will be displayed in the ComboBox itself? an example is the "Question tags" field on the page https://toster.ru/question/new
I create a ComboBox with ChexkBox like this

QStandardItemModel *model = new QStandardItemModel();
    for(int i=0;i<50;i++)
    {
        QStandardItem* item = new QStandardItem(QString::number(i));

        item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
        item->setData(Qt::Unchecked, Qt::CheckStateRole);
        model->setItem(i, 0, item);

    }
    ui->comboBox->setModel(model);

How now to intercept the click on the ChexkBox and display the list separated by commas in the ComboBox?
connect(?, ?, this, &form::onSetActivated);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mercury13, 2019-01-29
@Mercury13

I don't see a way through signals-slots.
Inherit from QStandardItemModel, stick on setModelData.
Better yet, inherit from QAbstractTableModel and override all these data(), flags()…

S
SerJook, 2019-01-30
@SerJook

See how it's done here
https://habr.com/ru/post/215289/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question