I have a QTableView
(model based) and I want to disable the editing capability of a particular cell, let's say row 0, column 1.
How can I do this? Please note that I still want other cells in this row enabled for editing.
If you are using a custom table model, you can implement the Qt::ItemFlags QAbstractItemModel::flags ( const QModelIndex & index ) const
method and return a set of flags where the Qt::ItemIsEditable
flag is not set for the cells you do not want to edit. Suppose MyTableModel
is inherited from QAbstractTableModel
:
Qt::ItemFlags MyTableModel::flags ( const QModelIndex & index ) const {
Qt::ItemFlags flags = Qt::NoItemFlags;
if (index.row() == 0 && index.column() == 1) {
return flags;
}
return flags | Qt::ItemIsEditable;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With