[Interest] How to make a column of a QTableView read-only?

K. Frank kfrank29.c at gmail.com
Sun Jul 1 20:50:49 CEST 2012

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.

I see two approaches:

Attach a delegate to the column that provides a null or no-op editor.

Drill down somehow to get the individual items, and set the ItemIsEditable
flag of their ItemFlags to false.

I've seen what appear to be these two methods suggested on various
Qt forums, but they both seem to a little bit roundabout for something
that is both simple and generally useful.  (I've also seen hints that a
simple method was available in Qt 3.)

Is there something simple and straightforward that I am overlooking
(like QTableView::setColumnReadonly (int columnIndex))?

Thanks for any pointers.

K. Frank

More information about the Interest mailing list