ComboBox of CheckBoxes?

前端 未结 4 534
离开以前
离开以前 2020-12-03 03:28

I am trying to make the items in a ComboBox checkable. I tried this:

http://programmingexamples.net/wiki/Qt/ModelView/ComboBoxOfCheckBoxes

where

4条回答
  •  一个人的身影
    2020-12-03 03:47

    You can try this with QListView:

    QStringList values = QStringList << "check 1" << "check 2" << "check 3" << "check 4";
    
    QStandardItemModel model = new QStandardItemModel;
    for (int i = 0; i < values.count(); i++)
    {
        QStandardItem *item = new QStandardItem();
        item->setText(values[i]);
        item->setCheckable(true);
        item->setCheckState(Qt::Unchecked);
        model->setItem(i, item);
    }
    
    ui->list->setModel(model);
    

提交回复
热议问题