[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
    @tableView.setEditTriggers(QAbstractItemView::NoEditTriggers);@

    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());
    
          if(toBeDisabled()){
                 QStandardItem *my_item = item_model->itemFromIndex(index);
                  my_item->setFlags(!Qt::ItemIsEditable);
          }
          else{
                    table_view->openPersistentEditor(index);
          }
          item_model->setData(index,0);
     }
    

    }@

    Thanks again.


Log in to reply
 

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