QTableView - not allow user to edit cell

Berschi picture Berschi · Aug 25, 2009 · Viewed 24.2k times · Source

I created a QTableView with a QSqlTableModel. By standard, double-clicking on the cells will mark them and the user can edit them. I want, that the user isn't allowed to do that. He is allowed to mark the whole row by clicking on a single cell, but not to edit the cell. How can I do that?

Answer

Harald Scheirich picture Harald Scheirich · Aug 25, 2009

Depending on whether you are coding everything or doing things in the designer, set

  • editTriggers to QAbstractItemView::NoEditTriggers
  • selectionBehavior to QAbstractItemView::SelectRows
  • optionally set selectionMode to QAbstractItemView::SingleSelection if you want the user to select exactly one row

on the tableview object the appropriate calls will all be prefixed with set e.g setEditTriggers() in the Designer you can find these option in the AbstractItemView section