[Qgis-developer] PyQT: how to set a column of QTableView read-only

Stefanie Tellex stefie10 at media.mit.edu
Fri Feb 27 08:09:50 EST 2009


I define a method like this in the table model:
    def flags(self, idx):
         baseflags = QAbstractTableModel.flags(self, idx)
         if idx.column() == COL_CLASS:
             return baseflags | Qt.ItemIsEditable
         else:
             return baseflags



Andreas Neumann pisze:
> Hi,
> 
> I am writing a PyQGIS plugin where I am using an editable QTableView. Some
> of the columns should be editable, but some should be read-only (e.g. the
> primary key column, or an automatically updated area or length column).
> 
> I didn't find a convenient way to set a single column read-only. Googling
> for this topic led me to some posts from 2006 suggesting that I should
> step through individual cells and set flags.
> 
> In Qt3 there was a convenient method
> QTableView.setColumnReadOnly(colIndex,True) - but in qt4 this method is
> gone ;-(
> 
> Any suggestions?
> 
> Thanks,
> Andreas
> 



More information about the Qgis-developer mailing list