TorAn
30th March 2010, 23:28
I have Qtreeview with the model derived from QAbstractTableModel.
All the items in the first column has to be checkable.
I implemented the flags() member function in the model that returns needed flag for the first item in each row.
Qt::ItemFlags mymodel::flags ( const QModelIndex & index ) const
{
if (! index.isValid())
return Qt::ItemFlag::NoItemFlags;
if (index.column() == 0)
{
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemFlag::ItemIsUserCheckable;
}
else
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}
Now, Qt::ItemFlags section of the documenation states:
checkable items need to be given both a suitable set of flags and an initial state, indicating whether the item is checked or not. This is handled automatically for model/view components
My question is: how to indicate that the "item" is checkable from within the model? I don't see any method in
QAbstractTableModel or in QModelIndex to do this.
Am I supposed to do somthing for CheckStateRole in the reimplemented "data" member functionЪ
QVariant mymodel::data(const QModelIndex& index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::TextAlignmentRole)
return int(Qt::AlignRight | Qt::AlignVCenter);
else if (role == Qt::CheckStateRole)
{
??
}
....
}
}
Any help will be greatly appreciated.
All the items in the first column has to be checkable.
I implemented the flags() member function in the model that returns needed flag for the first item in each row.
Qt::ItemFlags mymodel::flags ( const QModelIndex & index ) const
{
if (! index.isValid())
return Qt::ItemFlag::NoItemFlags;
if (index.column() == 0)
{
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemFlag::ItemIsUserCheckable;
}
else
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}
Now, Qt::ItemFlags section of the documenation states:
checkable items need to be given both a suitable set of flags and an initial state, indicating whether the item is checked or not. This is handled automatically for model/view components
My question is: how to indicate that the "item" is checkable from within the model? I don't see any method in
QAbstractTableModel or in QModelIndex to do this.
Am I supposed to do somthing for CheckStateRole in the reimplemented "data" member functionЪ
QVariant mymodel::data(const QModelIndex& index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::TextAlignmentRole)
return int(Qt::AlignRight | Qt::AlignVCenter);
else if (role == Qt::CheckStateRole)
{
??
}
....
}
}
Any help will be greatly appreciated.