import sysfrom PyQt5.QtWidgets import QApplication, QMainWindow, QTableViewfrom PyQt5.QtCore import QAbstractTableModel, Qtimport pandas as pdimport numpy as np# 构造10万行测试对账数据n = 100000df = pd.DataFrame({ "order_id": np.arange(n), "amount": np.round(np.random.uniform(1,1000,n),2), "trade_status": np.random.choice(["已完成","待处理","已取消"], size=n)})class CustomTableModel(QAbstractTableModel): def __init__(self, data): super().__init__() self._data = data def rowCount(self, parent=None): return len(self._data) def columnCount(self, parent=None): return self._data.shape[1] def data(self, index, role=Qt.DisplayRole): if index.isValid() and role == Qt.DisplayRole: return str(self._data.iloc[index.row(), index.column()]) return None def headerData(self, col, orientation, role): if orientation == Qt.Horizontal and role == Qt.DisplayRole: return self._data.columns[col] return Noneapp = QApplication(sys.argv)win = QMainWindow()win.resize(900,600)table = QTableView()model = CustomTableModel(df)table.setModel(model)win.setCentralWidget(table)win.show()sys.exit(app.exec_())