[Interest] QColumnView and QTreeView using same model
Tony Rietwyk
tony at rightsoft.com.au
Wed May 4 16:06:33 CEST 2022
On 4/05/2022 11:43 pm, Michael Jackson wrote:
> ...
> Now on to figure out how to display checkboxes next to each item. I've tried:
>
> Qt::ItemFlags ImportDataStructureModel::flags(const QModelIndex& index) const
> {
> if(!index.isValid())
> {
> return {};
> }
> return Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | QAbstractItemModel::flags(index);
> }
>
> Which does not seem to show anything. I'll probably have to create a custom delegate.
> --
> Mike Jackson
>
Hi Mike,
If you return flag ItemIsUserCheckable in your model, then you must also
return a valid variant with Qt::CheckState for data(Qt::CheckStateRole)
- it won't just assume Qt::Unchecked.
Ditto with the item widgets - besides item->setFlags, you need to call
item->setCheckState as well.
Tony
More information about the Interest
mailing list