accpert.com
accpert.com

Reputation: 129

qt designer certain columns of a QTableWidget editable

i have a QTableWidget created with Qt Designer and would like to know if it is possible to make certain columns editable and other not in Qt designer. I have seen solutions in python or c++ but i would like to know if it is possible in qt designer.

Upvotes: 1

Views: 1420

Answers (2)

eyllanesc
eyllanesc

Reputation: 244132

You won't be able to do it with Qt Designer since at most you can make the items created by QtDesigner non-editable (the items are editable by default) and not the new rows or columns created by code. So the simplest and most practical solution is to do it by code using a delegate as I point out in this post:

class ReadOnlyDelegate(QtWidgets.QStyledItemDelegate):
    def createEditor(self, parent, option, index):
        editable_columns = (1, 3, 4)
        if index.column() in editable_columns:
            return super().createEditor(parent, option, index)
delegate = ReadOnlyDelegate(self.qtable_widget)
self.tableWidget.setItemDelegate(delegate)

Upvotes: 2

Rolv Apneseth
Rolv Apneseth

Reputation: 2118

For a whole column, I don't think so. No flags are provided in the properties for the columns. If your table isn't too big, you could edit the items individually like so:

In the Designer, right-click the QTAbleWidget and click on Edit Items.... Then, switch over to the Items tab.

From there, click on any item and then open up the Properties << tab. In there you should find a checkbox for whether that specific item is editable or not.

Upvotes: 1

Related Questions