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?
+1
A:
Try this:
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
shoosh
2009-08-25 14:13:31
+1
A:
Toggle off the table item's ItemIsEditable bit. e.g.:
QTableWidgetItem* item = new QTableWidgetItem(...);
...
item->setFlags(item->flags() &= ~Qt::ItemIsEditable);
Rob
2009-08-25 14:14:15
+1
A:
Ideally you will want to use:
void QAbstractItemView::setItemDelegate ( QAbstractItemDelegate * delegate )
And then create a class that inherits from QItemDelegate like in this example.
Editing your class to have
QWidget * QItemDelegate::createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const
return NULL
or use:
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
You will also want to look at
void setSelectionBehavior ( QAbstractItemView::SelectionBehavior behavior )
With the parameter: QAbstractItemView::SelectRows
For reference: http://doc.trolltech.com/4.5/qtableview.html
Adam W
2009-08-25 14:17:08
+3
A:
Depending on whether you are coding everything or doing things in the designer, set
editTriggerstoQAbstractItemView::NoEditTriggersselectionBehaviortoQAbstractItemView::SelectRows- optionally set
selectionModetoQAbstractItemView::SingleSelectionif 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
Harald Scheirich
2009-08-25 14:28:23
it's called QAbstractItemView::NoEditTriggers, QAbstractItemView::SelectRows and QAbstractItemView::SingleSelection, but it's exactly what I was looking for. Thank you!
Berschi
2009-08-25 14:34:10