[solved] How to disable cells in QTableView

  • Dear all,

    I have QTableView which created using QStandardItemModel.

    I also create QSpinBox delegate to edit the cells data.

    But I have to disable some SpinBoxes to avoid change value by user.

    So my problem is how to disable some cells of QTabelView.

    I find some were recommended to use

    But it disable entire TableView.

  • You can use
    @void QStandardItem::setFlags(Qt::ItemFlags flags)@
    for that. "Flags":http://qt-project.org/doc/qt-5/qt.html#ItemFlag-enum .

  • qxoz,

    Thank you very much for your helping hand. Your solution is working fine.

    I used below code.

    for (int row = 0; row < rows().count(); ++row){
    for (int col = 0; col < cols().count(); ++col){

         QModelIndex index = item_model->index(row,col,QModelIndex());
                 QStandardItem *my_item = item_model->itemFromIndex(index);


    Thanks again.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.