Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Read only column



  • I have a QTableView.
    I'd like to have the first column set as "read only" and all the others editable.
    How can I obtain this?

    I read the documentation and other websites and i've understand I should overide Qt::ItemIsEditable flag

    Could you provide me some examples?

    Thanks


  • Lifetime Qt Champion

    Hi,

    You need to reimplement the flags(const QModelIndex &index) function of your model.

    Something like:

    @
    if (index.column() == 1) {
    return QAbstractModel::flags() & ~Qt::ItemIsEditable;
    }
    @


Log in to reply