2

In a QTableView we can control the background color as below.

class MyTableModel(QAbstractTableModel):
    def data(self, index, role):
        if index.isValid():
            if role == Qt.BackgroundRole:
                return QBrush(QColor(Qt.yellow))
            if role == Qt.DisplayRole:
                return self.get_value(index.row(), index.column())

However, If I set a stylesheet with following content:

QTableView::item
{
    border-style: none;
    border-bottom: 1px solid lightgrey;
}

The background color role does not have any effect. I want to set the background color programmatically based on some computation. How can this be achieved while still using QSS?

Suresh
  • 925
  • 1
  • 9
  • 23

0 Answers0