user12621047
user12621047

Reputation:

Can you set a specific colour for whole QTableWidget?

Ok so we can set a specific background color for a cell that contains data:

self.Table.item(0,i).setBackground(QColor(255,128,128)) 

Is it possible to set the whole table at initiation or during operations to a specific color? At initiation it doesn't contain any data so the cells are empty.

Upvotes: 0

Views: 94

Answers (1)

eyllanesc
eyllanesc

Reputation: 244301

If you want all cells to have that background color then you can use a delegate:

class Delegate(QStyledItemDelegate):
    def initStyleOption(self, option, index):
        super().initStyleOption(option, index)
        if not index.data(Qt.BackgroundRole):
            option.backgroundBrush = QBrush(QColor(255, 128, 128))
delegate = Delegate(self.Table)
self.Table.setItemDelegate(delegate)

Upvotes: 1

Related Questions