working color, but update from proxy does not change in database

This commit is contained in:
ccppi 2024-07-26 14:19:17 +02:00
parent 41f356e5bb
commit 2901badfe5

View File

@ -1,6 +1,6 @@
from PySide6.QtWidgets import QApplication, QWidget, QMainWindow, QTableWidget, QVBoxLayout, QTableWidgetItem, QPushButton, QHBoxLayout, QTableView, QLineEdit, QDialog, QLabel, QTextEdit, QCheckBox, QComboBox
from PySide6.QtWidgets import QApplication, QWidget, QMainWindow, QTableWidget, QVBoxLayout, QTableWidgetItem, QPushButton, QHBoxLayout, QTableView, QLineEdit, QDialog, QLabel, QTextEdit, QCheckBox, QComboBox, QStyledItemDelegate
from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtCore import QUrl,Qt,QSortFilterProxyModel, qDebug, QSize,QObject,QThread,Signal
from PySide6.QtCore import QUrl,Qt,QSortFilterProxyModel, qDebug, QSize,QObject,QThread,Signal,QAbstractTableModel
from PySide6.QtSql import QSqlDatabase, QSqlTableModel, QSqlQueryModel, QSqlQuery
from PySide6 import QtGui
from db import addFineFilter
@ -12,13 +12,33 @@ DBFILE = "../db/sqlite3.db"
Cantons = ["AG","ZH","BE","SG","SO"]
class TableModel(QAbstractTableModel):
def __init__(self, data):
super(TableModel, self).__init__()
self._data = data
def data(self, index, role):
if role == Qt.BackgroundRole:
return QtGui.QColor('#9C0006')
class ColorDelegate(QStyledItemDelegate):
currentRow = 0
starred = 0
def initStyleOption(self,option,index):
super().initStyleOption(option,index)
data = index.data()
try:
value = float(data)
except:
print("error not an integer")
else:
print("data:",data)
self.currentRow = index.row()
print("row: ",self.currentRow)
if value == 1:
self.starred = 1
#option.backgroundBrush = QtGui.QColor("green")
else:
self.starred = 0
#option.backgroundBrush = QtGui.QColor("grey")
if self.starred == 1:
option.backgroundBrush = QtGui.QColor("red")
else:
option.backgroundBrush = QtGui.QColor("white")
class ValidationWorker(QObject):
finished = Signal()
@ -70,6 +90,10 @@ class MainWindow(QMainWindow):
self.view = QTableView()
self.view.setModel(self.model)
delegate = ColorDelegate(self.view)
self.view.setItemDelegate(delegate)
self.setProxyViewSettings()
self.view.clicked.connect(self.cell_clicked)
@ -193,8 +217,8 @@ class MainWindow(QMainWindow):
self.model.setTable("")
self.model.setQuery(cmd +" ;")
self.proxymodel2 = QSortFilterProxyModel(self)
self.proxymodel2.setSourceModel(self.model)
#self.proxymodel2 = QSortFilterProxyModel(self)
#self.proxymodel2.setSourceModel(self.model)
self.view.setModel(self.proxymodel2)
self.setProxyViewSettings()
class PWPrompt(QDialog):