qtqt4qtablewidget

How to make a column in QTableWidget read only?


I would like to have one column in QTableWidget NOT editable.
In forums I have read a lot about some flags but could not manage to implement.


Solution

  • Insert into the QTableWidget following kind of items:

    QTableWidgetItem *item = new QTableWidgetItem();
    item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
    

    Works fine!

    EDIT:

    QTableWidgetItem *item = new QTableWidgetItem();
    item->setFlags(item->flags() ^ Qt::ItemIsEditable);
    

    This is a better solution. Thanks to @priomsrb.