Yes, you have to return proper flags from your flags() implementation.
Yes, you have to return proper flags from your flags() implementation.
sorry, I am not being clear. There is no implementation example of "setflags()" or something. The implemebntation of flags in the editabletreemodel example is
Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
{
[...]
}
I don't understand when this is called. It seems to be done automatically when the treemodel is viewed? How can I set a flag of an item at a given index?
thanks
You don't set a flag, you return flags whenever someone asks for them. When the model tells the environment that a particular index has changed its data, all the views will probably re-ask for the flags so at this point you may return something different than before.
Qt Code:
Qt::ItemFlags MyModel::flags(...) const { Qt::ItemFlags defFlags = BaseClass::flags(index); if(shouldBeDisabled(index)) defFlags &= ~Qt::ItemIsEnabled; return defFlags; };To copy to clipboard, switch view to plain text mode
thanks, that got me further. Disabling a parent does not disable the children. After some trying my solution is as follows: when a certain branch has to be disabled I take the row of the parent of that branch, and in flags the only line to be added is:
if (index.row() == rowdisable|| index.parent().row() == rowdisable)
flags &= ~Qt::ItemIsEnabled;
rowdisable is an integer and member of the treemodel
Bookmarks