From 8682ba0be23dfc6b66af7bc71bbe423aba4d0e16 Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Tue, 26 Sep 2023 15:03:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D1=8C=D0=BD=D1=83=D1=8E=20=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=81=D0=B8=D1=8E=20datamodel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- statapp/main_window.py | 4 +++- statapp/models/data_model.py | 46 ++++++++++++++++++++++++++++++++++++ statapp/ui/main_window.ui | 8 +++++-- statapp/ui/ui_main_window.py | 4 ++-- 4 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 statapp/models/data_model.py diff --git a/statapp/main_window.py b/statapp/main_window.py index ec9ec0a..45dc63c 100644 --- a/statapp/main_window.py +++ b/statapp/main_window.py @@ -1,6 +1,6 @@ -from PySide6.QtCore import Slot from PySide6.QtWidgets import QMainWindow +from statapp.models.data_model import DataModel from statapp.ui.ui_main_window import Ui_MainWindow @@ -10,3 +10,5 @@ class MainWindow(QMainWindow): self.ui = Ui_MainWindow() self.ui.setupUi(self) + self.model = DataModel() + self.ui.tableView.setModel(self.model) diff --git a/statapp/models/data_model.py b/statapp/models/data_model.py new file mode 100644 index 0000000..5101ba3 --- /dev/null +++ b/statapp/models/data_model.py @@ -0,0 +1,46 @@ +import numpy as np +from PySide6 import QtCore +from PySide6.QtCore import Qt + + +class DataModel(QtCore.QAbstractTableModel): + def __init__(self, data=np.array([[1, 2, 3], [4, 5, 6]])): + super().__init__() + + self._data = data + + def rowCount(self, index): + return self._data.shape[0] + + def columnCount(self, index): + return self._data.shape[1] + + def headerData(self, section: int, orientation: Qt.Orientation, role: int = ...): + if role == Qt.DisplayRole: + if orientation == Qt.Orientation.Horizontal: + + if section == 0: + return 'Y' + + return f'X{section}' + + return None + + def flags(self, index): + return Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable + + def setData(self, index, value, role): + if role == Qt.EditRole: + try: + value = int(value) + except ValueError: + return False + self._data[index.row(), index.column()] = value + return True + return False + + def data(self, index, role): + if role == Qt.DisplayRole: + return int(self._data[index.row(), index.column()]) + + return None diff --git a/statapp/ui/main_window.ui b/statapp/ui/main_window.ui index f00abb1..526de21 100644 --- a/statapp/ui/main_window.ui +++ b/statapp/ui/main_window.ui @@ -26,7 +26,11 @@ - + + + false + + @@ -36,7 +40,7 @@ 0 0 800 - 22 + 27 diff --git a/statapp/ui/ui_main_window.py b/statapp/ui/ui_main_window.py index 15b890f..424333c 100644 --- a/statapp/ui/ui_main_window.py +++ b/statapp/ui/ui_main_window.py @@ -39,13 +39,14 @@ class Ui_MainWindow(object): self.tableView = QTableView(self.centralwidget) self.tableView.setObjectName(u"tableView") + self.tableView.verticalHeader().setVisible(False) self.gridLayout.addWidget(self.tableView, 1, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QMenuBar(MainWindow) self.menubar.setObjectName(u"menubar") - self.menubar.setGeometry(QRect(0, 0, 800, 22)) + self.menubar.setGeometry(QRect(0, 0, 800, 27)) self.filemenu = QMenu(self.menubar) self.filemenu.setObjectName(u"filemenu") self.generatemenu = QMenu(self.menubar) @@ -83,4 +84,3 @@ class Ui_MainWindow(object): self.modelmenu.setTitle(QCoreApplication.translate("MainWindow", u"\u041c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435", None)) self.helpmenu.setTitle(QCoreApplication.translate("MainWindow", u"\u0421\u043f\u0440\u0430\u0432\u043a\u0430", None)) # retranslateUi -