@@ -0,0 +1,1668 @@
+#!/usr/bin/env python3%0A# -*- coding: utf-8 -*-%0A%0A# Ref:%0A# - http://doc.qt.io/qt-5/model-view-programming.html#sorting%0A# - http://doc.qt.io/qt-5/model-view-programming.html#proxy-models%0A# - http://doc.qt.io/qt-5/qsortfilterproxymodel.html#sorting%0A# - https://stackoverflow.com/a/11606946%0A%0Aimport numpy as np%0Aimport sys%0Afrom PyQt5.QtCore import Qt, QAbstractTableModel, QVariant, QSortFilterProxyModel%0Afrom PyQt5.QtWidgets import QApplication, QTableView%0A%0A%0Aclass MyModel(QAbstractTableModel):%0A%0A    def __init__(self, parent):%0A        super().__init__(parent)%0A%0A        self.data = np.random.randint(0, 9, (10, 3))%0A%0A    def rowCount(self, parent):%0A        return self.data.shape%5B0%5D%0A%0A    def columnCount(self, parent):%0A        return self.data.shape%5B1%5D%0A%0A    def data(self, index, role):%0A        if role == Qt.DisplayRole:%0A            return %22%7B%7D%22.format(self.data%5Bindex.row(), index.column()%5D)%0A%0A        return QVariant()%0A%0Aif __name__ == '__main__':%0A    app = QApplication(sys.argv)%0A%0A    table_view = QTableView()%0A    my_model = MyModel(None)%0A%0A    proxyModel = QSortFilterProxyModel()   #%C2%A0%3C--%0A    proxyModel.setSourceModel(my_model)    #%C2%A0%3C--%0A    table_view.setModel(proxyModel)        #%C2%A0%3C--%0A    #table_view.setModel(my_model)%0A%0A    table_view.setSortingEnabled(True)     #%C2%A0%3C--%0A%0A    table_view.show()%0A%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)

Add a snippet.