alab
alab

Reputation: 31

How to make QTableWidget cells read only using PYQT5?

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

Answers (3)

Alex
Alex

Reputation: 1

In PyQt6 you can do:

item1.setFlags(item1.flags() ^ Qt.ItemFlag.ItemIsEditable)

Upvotes: 0

Luan Nguyen
Luan Nguyen

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

Anurag Singh
Anurag Singh

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

Related Questions