Hi Sean! Thank you for the suggestion.
On Sun, Jul 1, 2012 at 3:11 PM, Sean Harmer <s...@theharmers.co.uk> wrote: > Hi K. Frank, > > On 01/07/2012 19:50, K. Frank wrote: >> Hello List! >> >> I have a QTableView (backed by a QSqlTableModel) and am looking >> for a simple way to make a column read-only. Poking around in the >> documentation, I don't see anything obviously simple. > > Take a look at the function QAbstractItemModel::flags(). You can > override this in your model such that flags it returns do not include > Qt::ItemIsEditable for the column you wish to be read-only. To make sure I understand: In my concrete case, I would then derive from QSqlTableModel, override its flags() member function, and add to the derived class some kind of setColumnReadonly() member function (or add some kind of readonlyColumnIndex to its constructor) to tell flags() which columns to flag as read-only. Is that the idea? Also, do i take it correctly from your answer that there isn't another way that is clearly simpler? For me, this approach is fine. But, as an aside, read-only can be either a model attribute (if the model is read-only or const) or a view attribute (if you have a read-only view into a non-read-only model). In my case, I have only one view into the model, so I can use your suggested approach to make (a column of) the model read-only. But, for future reference, what's the best way to make the view read-only? (For example, what if my application has two views into the same model, only one of which should be read-only?) > Sean Thanks for any additional thoughts. K. Frank _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest