1

I have a QTableWidget in my dialog. I want to make some cells read only. How do I do that using PYQT5?

halfer
  • 19,824
  • 17
  • 99
  • 186
alab
  • 31
  • 1
  • 2
  • I thought this was a dupe of [this question](https://stackoverflow.com/questions/2574115/how-to-make-a-column-in-qtablewidget-read-only), but that is about columns, not cells. – halfer Jun 05 '19 at 13:13

2 Answers2

3

To make particular cell of a QTableWidget read only:

item = QTableWidgetItem()
item.setFlags(item.flags() ^ Qt.ItemIsEditable)
tableName.setItem(row, column, item)

Just change flags to change the behavior/properties of the cell.

Reference answer is @Narek

Anurag Singh
  • 492
  • 6
  • 16
0

The below code can set a specific QTableWidget cell item as read-only for PyQt5. The cell item can be assigned before being set as read-only.

from PyQt5.QtCore import Qt

cell_item = tableWidget.item(i, j)
cell_item .setFlags(cell_item.flags() ^ Qt.ItemIsEditable)