There is a nice example of how to achieve "PyQt Tableview background color based on text value" since I am not allowed to comment I have to open a new question.
How can I compare column "id" as integer numbers? e.g. if (id>103) and (id<106)?
Code line taken from link above:
if QSqlQueryModel.data(self, self.index(item.row(), 2), Qt.DisplayRole) == "Young":
seems to work fine for text, but
if QSqlQueryModel.data(self, self.index(item.row(), 0), Qt.DisplayRole) > "103":
would compare as text not as integer, and
if QSqlQueryModel.data(self, self.index(item.row(), 0), Qt.DisplayRole).toInt() > 103:
gives an AttributeError: 'QVariant' object has no attribute 'toInt'
How to compare cell values as integer, float, boolean, ...?