Pyqt Tableview Background Color Based On Text Value Rather Than True Or False
Follow up to my general question, where @eyllanesc has kindly answered my question. Out of curiosity, I tried changing to code to check against a string rather than 1 and all the r
Solution 1:
You should check the condition inside if role == Qt.BackgroundRole
defdata(self, item, role):
if role == Qt.BackgroundRole:
if QSqlQueryModel.data(self, self.index(item.row(), 2), Qt.DisplayRole) == "Young":
return QBrush(Qt.yellow)
if role == Qt.DisplayRole:
if item.column() == 3:
returnTrueif QSqlQueryModel.data(self, item, Qt.DisplayRole) == 1elseFalsereturn QSqlQueryModel.data(self, item, role)
Post a Comment for "Pyqt Tableview Background Color Based On Text Value Rather Than True Or False"