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

How to make readonly one column of the QtableView?



  • Hi,
    I've got belove code. And I need to mak 3th columnn readonly. How can I do that?..

    QStandardItemModel  *modelFisDetay;
     this->modelFisDetay = new QStandardItemModel(1, 6, this);
    
    ui->tVFisDetay->setModel(modelFisDetay);
        
        modelFisDetay->setHeaderData(0, Qt::Horizontal, QObject::tr("Depo Kodu"));
        modelFisDetay->setHeaderData(1, Qt::Horizontal, QObject::tr("Stok Kodu"));
        modelFisDetay->setHeaderData(2, Qt::Horizontal, QObject::tr("Stok Adı"));
        modelFisDetay->setHeaderData(3, Qt::Horizontal, QObject::tr("Birim"));
        modelFisDetay->setHeaderData(4, Qt::Horizontal, QObject::tr("Miktar"));
        modelFisDetay->setHeaderData(5, Qt::Horizontal, QObject::tr("Açıklama"));
    
    //Adding row
    
    QList<QStandardItem *> rowData;
            rowData << new QStandardItem(QString(""));
    
            modelFisDetay->appendRow(rowData);
    
    
    

    Regards,
    Mucip:)


  • Lifetime Qt Champion

    Hi
    You can use
    void QStandardItem::setFlags
    and unset editable and maybe also selectable
    https://stackoverflow.com/questions/45413555/how-to-unset-a-flag-in-qt



  • Hi,
    I made below code.

     QList<QStandardItem *> rowData;
            rowData << new QStandardItem(QString("")); //depo
            rowData << new QStandardItem(QString("")); //stok kod
    
            QStandardItem *item = new QStandardItem(QString(""));
            item->setFlags(Qt::NoItemFlags);
    
            rowData << item; //stok ad
    
            modelFisDetay->appendRow(rowData);
    

    Thanks...

    Regards,
    Mucip:)


Log in to reply