At least you need to insert a single column to your model:
{
insertColumn(0); // important
}
CheckModel::CheckModel() : QStandardItemModel()
{
insertColumn(0); // important
}
To copy to clipboard, switch view to plain text mode
You might also want to return a bit more flags (the base class implementation returns a combination of ItemIsEnabled and ItemIsSelectable):
{
};
Qt::ItemFlags flags(const QModelIndex & index)
{
return QStandardItemModel::flags(index) | Qt::ItemIsUserCheckable;
};
To copy to clipboard, switch view to plain text mode
Also, when adding your items, you might need to initialize the check state:
comboBox->setItemData(idx, Qt::Unchecked, Qt::CheckStateRole);
comboBox->setItemData(idx, Qt::Unchecked, Qt::CheckStateRole);
To copy to clipboard, switch view to plain text mode
Bookmarks