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 -