@@ -0,0 +1,2084 @@
+#!/usr/bin/env python3%0A# -*- coding: utf-8 -*-%0A%0A# Ref: http://doc.qt.io/qt-5/modelview.html#2-1-a-read-only-table%0A%0Aimport sys%0Afrom PyQt5.QtCore import Qt, QAbstractTableModel, QVariant, QModelIndex%0Afrom PyQt5.QtWidgets import QApplication, QTableView%0A%0A###############################################################################%0A%0Aclass MyModel(QAbstractTableModel):%0A%0A    def __init__(self, parent=None):%0A        super().__init__(parent)%0A%0A        self._data = %5B%5B0, 0, 0%5D, %5B0, 0, 0%5D%5D   # CAUTION: don't call this %22self.data%22, it's already taken by %22self.data(...)%22%0A%0A    def rowCount(self, parent):%0A        return len(self._data)%0A%0A    def columnCount(self, parent):%0A        return len(self._data%5B0%5D)%0A%0A    def data(self, index, role):%0A        if role == Qt.DisplayRole:%0A            return self._data%5Bindex.row()%5D%5Bindex.column()%5D%0A        return QVariant()%0A%0A    def setData(self, index, value, role):%0A        if role == Qt.EditRole:%0A            self._data%5Bindex.row()%5D%5Bindex.column()%5D = value%0A%0A            # The following line are necessary e.g. to dynamically update the QSortFilterProxyModel%0A            self.dataChanged.emit(index, index, %5BQt.EditRole%5D)%0A%0A        return True%0A%0A    def flags(self, index):%0A        return Qt.ItemIsSelectable %7C Qt.ItemIsEditable %7C Qt.ItemIsEnabled%0A%0A%0Aif __name__ == '__main__':%0A    app = QApplication(sys.argv)%0A%0A    table_view = QTableView()%0A    my_model = MyModel()%0A    table_view.setModel(my_model)%0A    table_view.show()%0A%0A    # GIVE FOCUS TO CELL(1,1) IN EDIT MODE!%0A    # https://pyqt.riverbankcomputing.narkive.com/mIxVZuAN/how-to-give-focus-to-a-particular-cell-in-qtableview%0A    index = my_model.index(1, 1)%0A    table_view.setCurrentIndex(index)%0A    table_view.edit(index)%0A%0A    # The mainloop of the application. The event handling starts from this point.%0A    # The exec_() method has an underscore. It is because the exec is a Python keyword. And thus, exec_() was used instead.%0A    exit_code = app.exec_()%0A%0A    # The sys.exit() method ensures a clean exit.%0A    # The environment will be informed, how the application ended.%0A    sys.exit(exit_code)%0A

Add a snippet.