I dunno something with colors

This commit is contained in:
ccppi 2024-07-26 15:29:06 +02:00
parent 2901badfe5
commit 5c580adf7f
2 changed files with 48 additions and 7 deletions

View File

@ -22,11 +22,12 @@ class ColorDelegate(QStyledItemDelegate):
try:
value = float(data)
except:
print("error not an integer")
pass
#print("error not an integer")
else:
print("data:",data)
#print("data:",data)
self.currentRow = index.row()
print("row: ",self.currentRow)
#print("row: ",self.currentRow)
if value == 1:
self.starred = 1
#option.backgroundBrush = QtGui.QColor("green")
@ -86,6 +87,7 @@ class MainWindow(QMainWindow):
self.model = QSqlTableModel(self)
self.model.setTable("jobs")
self.model.setEditStrategy(QSqlTableModel.OnFieldChange)
self.model.select()
self.view = QTableView()
@ -121,7 +123,7 @@ class MainWindow(QMainWindow):
self.view.setColumnWidth(5,10)
self.view.hideColumn(7)
self.view.setSortingEnabled(True)
self.view.clicked.connect(self.cell_clicked)
def runWorker(self):
self.thread = QThread()
self.worker = Worker()
@ -216,10 +218,11 @@ class MainWindow(QMainWindow):
print("Run SQL Query",cmd)
self.model.setTable("")
self.model.setQuery(cmd +" ;")
#self.model.setTable("jobs")
#self.proxymodel2 = QSortFilterProxyModel(self)
#self.proxymodel2.setSourceModel(self.model)
self.view.setModel(self.proxymodel2)
self.view.setModel(self.model)
self.setProxyViewSettings()
class PWPrompt(QDialog):
def __init__(self):

38
lib/qsqlmod.py Normal file
View File

@ -0,0 +1,38 @@
#modifie the QSqlQueryModel to be editable and sets them to the database
#credits to :
#https://stackoverflow.com/questions/49752388/editable-qtableview-of-complex-sql-query
class SqlQueryModel_editable(QSqlQueryModel):
"""a subclass of QSqlQueryModel where individual columns can be defined as editable
"""
def __init__(self, editables):
"""editables should be a dict of format:
{INT editable_column_nr : (STR update query to be performed when changes are made on this column
INT model's column number for the filter-column (used in the where-clause),
)}
"""
super().__init__()
self.editables = editables
def flags(self, index):
fl = QSqlQueryModel.flags(self, index)
if index.column() in self.editables:
fl |= Qt.ItemIsEditable
return fl
def setData(self, index, value, role=Qt.EditRole):
if role == Qt.EditRole:
mycolumn = index.column()
if mycolumn in self.editables:
(query, filter_col) = self.editables[mycolumn]
filter_value = self.index(index.row(), filter_col).data()
q = QSqlQuery(query.format(value, filter_value))
result = q.exec_()
if result:
self.query().exec_()
else:
print(self.query().lastError().text())
return result
return QSqlQueryModel.setData(self, index, value, role)