def data(self, item, role):
# Changing color if "reserved" is True
if role == QtCore.Qt.BackgroundRole:
if item.row() % 2: # alternating background color
# dark
if QtSql.QSqlQueryModel.data(self, self.index(item.row(), 7), QtCore.Qt.DisplayRole) == 1:
return QtGui.QBrush(QtGui.QColor.fromRgb(176, 234, 153))
if QtSql.QSqlQueryModel.data(self, self.index(item.row(), 7), QtCore.Qt.DisplayRole) == 2:
return QtGui.QBrush(QtGui.QColor.fromRgb(234, 189, 190))
else:
# light
if QtSql.QSqlQueryModel.data(self, self.index(item.row(), 7), QtCore.Qt.DisplayRole) == 1:
return QtGui.QBrush(QtGui.QColor.fromRgb(198, 247, 178))
if QtSql.QSqlQueryModel.data(self, self.index(item.row(), 7), QtCore.Qt.DisplayRole) == 2:
return QtGui.QBrush(QtGui.QColor.fromRgb(250, 217, 218))
return QtSql.QSqlQueryModel.data(self, item, role)
评论列表
文章目录