Reputation: 1286
I create a QTableWidget with:
self.table = QtGui.QTableWidget()
self.table.setObjectName('table')
self.table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
verticalLayout.addWidget(self.table)
with this selection it is possible to select rows but I don't want that the user can edit any cells of this table. I know that you can enable each cell while filling the table. But is there a possibility to set the cells of the whole table kind of inactive (after the filling of the table) while the selection of the rows is still possible?
TIA Martin
Upvotes: 8
Views: 22607
Reputation: 3697
You can disable editing by setting the flags ItemIsSelectable
and ItemIsEnabled
for each item in your table:
table = QTableWidget(10,10)
for i in range(10):
for j in range(10):
item = QTableWidgetItem(str(i*j))
item.setFlags( Qt.ItemIsSelectable | Qt.ItemIsEnabled )
table.setItem(i, j, item)
Upvotes: 5
Reputation: 3976
use
self.table.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
(here you can find other triggers, just in case you need them)
Upvotes: 16