[Qt] QStandardItemModel and checkbox
-
Hi all:
I have a custom model derived from QStandardItemModel and set setCheckable(true) for each QStandardItem. the view is QTreeView.
I want to do is whenever I click on node's checkbox, the checkState will flip between check/uncheck. other nodes(parent especially) will be Check/Uncheck/PartiallyChecked.
tristate enabled also
@
Qt::ItemFlags FileSystemModel::flags(const QModelIndex & index) const
{
return QStandardItemModel::flags(index) | Qt::ItemIsTristate;
}
@I've try to modify value in QStandardItemModel::setData
@
bool FileSystemModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
QVariant new_value=value;if (role==Qt::CheckStateRole) { auto check = static_cast<Qt::CheckState> (value.toUInt()); if (check==Qt::PartiallyChecked) new_value = Qt::Unchecked; } return QStandardItemModel::setData(index,new_value,role);
}
@but it not work.
any ideas?