Reputation: 31
I have a QTableWidget in my dialog. I want to make some cells read only. How do I do that using PYQT5?
Upvotes: 1
Views: 4347
Reputation: 1
In PyQt6 you can do:
item1.setFlags(item1.flags() ^ Qt.ItemFlag.ItemIsEditable)
Upvotes: 0
Reputation: 1
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)
Upvotes: 0
Reputation: 492
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
Upvotes: 3