View Full Version : No delegate for 1 column in QTreeView

15th February 2007, 11:02
I've got a QTreeView with 3 columns and I'm using the default delegate implementation to edit the contents of the items in columns 2 and 3. But I'd like to disable the editor in column 1. What would be the easiest way to achieve this behaviour in QT 4.2.2?
Thanks a lot

15th February 2007, 11:55

Before the tree view launches the editor of your delegate, for an item, it uses the
flags method of your model implementation to check if the item can be
edited, so you simply mustn't return the Qt::ItemIsEditable flag for the first column
of your model.

Here an example implementation of the flags method:

Qt::ItemFlags CMyModel::flags( const QModelIndex& idx ) const {

if(! idx.isValid( ) )
return Qt::ItemIsEnabled;

Qt::ItemFlags def = Qt::ItemIsEnabled | Qt::ItemIsSelectable;

if( idx.column( ) == 0 )
return def;

return def | Qt::ItemIsEditable;