datenbankmodel

This commit is contained in:
2024-11-07 15:12:53 +01:00
parent bbad3b5fcb
commit 24a5255bac
5 changed files with 139 additions and 108 deletions

44
lib/DataBase.py Normal file
View File

@@ -0,0 +1,44 @@
# This Python file uses the following encoding: utf-8
import sys
import os
import sqlite3
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)