In this PyQt5 Tutorial, we are going to learn how we can use QStyledItemDelegate class to set certain rows or certain columns Read-Only on a QTableWidget.
Buy Me a Coffee? Your support is much appreciated!
PayPal Me: https://www.paypal.me/jiejenn/5
Venmo: @Jie-Jenn
Source Code:
import sys
from PyQt5.QtWidgets import QApplication, QTableWidget, QStyledItemDelegate
class ReadOnlyDelegate(QStyledItemDelegate):
def createEditor(self, parent, option, index):
print('createEditor event fired')
return
class AppDemo(QTableWidget):
def __init__(self):
super().__init__(5, 5)
self.resize(1500, 1500)
for i in range(5):
self.setColumnWidth(i, 250)
self.setRowHeight(i, 100)
delegate = ReadOnlyDelegate(self)
self.setItemDelegateForRow(1, delegate)
self.setItemDelegateForColumn(0, delegate)
app = QApplication(sys.argv)
demo = AppDemo()
demo.show()
sys.exit(app.exec_())