Question about Delegates in QTableView
-
Hi guys :)
I have delegate from QStyledItemDelegate. In my TableView i want to make a specified cell read only. I want to do it in delegate. How can i do that?Second Question: How can i get editor of a specified cell in delegate class?
Thanks :)
-
I don't know if this will work but you can try reimplement a createEditor. Something like this:
@
QWidget * MyDelegate::createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
QWidget* editor = QStyledItemDelegate::createEditor( parent, option, index );
// cast or something and set readOnly?
return editor;
}
@ -
Hi,
regarding your two questions:
1.) makes no sense in the delegate. The delegate comes into the game for handling editors and painting, not for data access. If you have to make changes on the data level, make it in a proxy model.
2.) The delegate creates the editors, where do you need to get an editor for a specific cell in the delegate?
-
If you want the a particular cell to be read only (i.e. not editable) then the model its associated with should return the appropriate "ItemFlags":http://doc.qt.digia.com/4.7-snapshot/qt.html#ItemFlag-enum for that index from its "flags":http://doc.qt.digia.com/4.7-snapshot/qabstractitemmodel.html#flags method (probably just ItemIsSelectable and ItemIsEnabled). This should not be done in a delegate, its not what they're for.
-
Ok thanks :) i got it. i'll do it in my proxy model :)