Files
pyqcrm/lib/DataBase.py
2024-11-07 16:39:56 +01:00

42 lines
1.1 KiB
Python

# This Python file uses the following encoding: utf-8
from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot
class DataBase(QAbstractTableModel):
def __init__(self, con):
super().__init__()
self.con = con
self.__data = self.__getData()
def __getData(self):
cursor = self.con.cursor()
cursor.execute("SELECT * FROM test")
return cursor.fetchall()
def rowCount(self, parent= QModelIndex()):
return len (self.__data)
def columnCount(self, parent= QModelIndex()):
return 3
def data(self, index, role= Qt.DisplayRole):
if role == Qt.DisplayRole:
row, col = index.row(), index.column()
return self.__data[row][col]
return None
def headerData(self, section, orientation, role= Qt.DisplayRole):
header= ["ID", "Kundenname", "Ort"]
if orientation == Qt.Horizontal and role ==Qt.DisplayRole:
return header[section]
return super().headerData(section, orientation, role)
#return None
@Slot(int)
def onRowClicked(self, row):
print(row)