Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QTableView readonly columns....
jammulak last edited by
I am developing an enterprise application using NokiaQT SDK. I have used Sqlite DB and Qtableview for showing data in forms and to edit tha data via UI. My problem is I want to make one or two columns readonly.
Can you please give solution with out subclassing QTableView because I have derived class from QWidget and using QTableview as a member.
Eddy last edited by
have a look at
@setItemDelegateForColumn ( int column, QAbstractItemDelegate * delegate )@
You will need a readonly delegate. There is an example on how to do this :
read the whitepaper "Qt 4's Model/View Delegates"
You will find the link to download "here":http://www.qtrac.eu/marksummerfield.html
dialingo last edited by
No need to use a delegate.
@Qt::ItemFlags QAbstractItemModel::flags ( const QModelIndex & index ) const@
This way you can specify for each cell the properties, like editable, dragable ...
ZapB last edited by
The flags method is the one to use.
andre last edited by
Indeed, use the flags method. You can either do that by subclassing the actual model, or by using a proxy model that just overrides the flags method to return the correct flags. There is an, perhaps already usuable, "example":http://developer.qt.nokia.com/wiki/QSortFilterProxyModel_subclass_for_readonly_columns_columns_with_checkboxes_and_password_columns on how to do this on the wiki. The class presented there can already make columns read only.
derf_r last edited by
For my use, the Eddy's solution is better.
In the example there is 2 classes, I use only only one.
Thank you very much