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