Auto-closing or self-closing, are some of the terms to describe when you insert a character (starting tag) that has a matched pair such as (, [, {, “, the feature will automatically insert the closing tag for you. In this# PyQt5 tutorial, we are going to learn how to implement this feature in Python.

PS: This is a more advanced tutorial, so it is recommended you have some experience creating PyQt5 programs.

Buy Me a Coffee? Your support is much appreciated!
PayPal Me:
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')

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()