你能为整个 QTableWidget 设置一个特定的颜色吗?

Can you set a specific colour for whole QTableWidget?

好的,我们可以为包含数据的单元格设置特定的背景颜色:

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

是否可以在启动时或操作期间将整个 table 设置为特定颜色?启动时它不包含任何数据,因此单元格为空。

如果您希望所有单元格都具有该背景色,那么您可以使用委托:

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)