QStandardItemModel *model = new QStandardItemModel(); model->appendRow(new QStandardItem("Item 1")); model->appendRow(new QStandardItem("Item 2")); model->appendRow(new QStandardItem("Item 3")); QComboBox *comboBox = new QComboBox(); comboBox->setModel(model);
QStringListModel *model = new QStringListModel(); QStringList list; list << "Item 1" << "Item 2" << "Item 3"; model->setStringList(list); QComboBox *comboBox = new QComboBox(); comboBox->setModel(model);
class CheckBoxDelegate : public QStyledItemDelegate { public: CheckBoxDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {} QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const override { QCheckBox *checkBox = new QCheckBox(parent); checkBox->setStyleSheet("QCheckBox::indicator { width: 20px; height: 20px; }"); return checkBox; } void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const override { editor->setGeometry(option.rect); } }; QStandardItemModel *model = new QStandardItemModel(); model->appendRow(new QStandardItem("Item 1")); model->appendRow(new QStandardItem("Item 2")); model->appendRow(new QStandardItem("Item 3")); QComboBox *comboBox = new QComboBox(); comboBox->setItemDelegate(new CheckBoxDelegate()); comboBox->setModel(model);Package library: The package library for QComboBox is part of the Qt framework, specifically the QtWidgets module. Therefore, the package that needs to be installed is the Qt library, which includes the QtWidgets module.