PDA

View Full Version : Flags of a list model



woodtluk
8th October 2010, 11:53
Hi there

I've got a list model that is derived from QAbstractListModel. There I try to set the flags:


Qt::ItemFlags MembersListModel::flags(const QModelIndex& index) const {
if(index.isValid())
return Qt::ItemIsEnabled;
}

Later I want to set different flags for different kinds of items.

But somehow this is not working at all. All the items are selectable and checkable (with a checkbox).
What am I doing wrong? Could it be that I missed something in the delegate?

Thx Luke

wysota
8th October 2010, 11:58
Does the declaration of your flags method contain a QModelIndex() as the default argument for the index parameter?

woodtluk
8th October 2010, 12:08
No it doesn't.
The declaration looks like this:

virtual Qt::ItemFlags flags ( const QModelIndex & index ) const;

I suppose there shouldn't be a default argument. There is none in the base class. And it not working either with the default argument;

wysota
8th October 2010, 12:17
No it doesn't.
I suppose there shouldn't be a default argument. There is none in the base class. And it not working either with the default argument;
Eeem, sorry, my fault, I got carried away. Default argument should be only for the parent arguments. Check if you have those everywhere.

As for your problem, check if your method is called at all, it probably isn't.

As for the checkable problem, it is likely your data() method is incorrect. You are probably not retuning an invalid QVariant for Qt::CheckStateRole.

woodtluk
8th October 2010, 12:45
Thanks!

I didn't handle the Qt::CheckStateRole in the data() method.

There is still a topic with the selection. But I think it's a similar thing in the delegate..

cheers Luke