QTableWidget - 更改行颜色 [英] QTableWidget - Change the row color
问题描述
我正在尝试更改 QTableWidget 行的背景颜色.还有一些其他关于同一件事的帖子,但没有一个给定的解决方案对我有用.
I'm trying to change the background color of a QTableWidget row. There are some others posts about the same thing but none of the given solutions worked for me.
使用该解决方案,我们将表中现有项目的背景设置为第 0 行第 1 列项目的浅灰色:
With that solution, we are setting the background on an already existing item in the table to a light grey on the item at row 0, column 1:
self.table.item(1,0).setBackground(QtGui.QColor(125,125,125))
它正在工作,但如果您有多个表,则为迭代行设置背景需要更多时间.我需要一个函数来通过仅传递行索引来更改行背景!
It's working, but set background for the row with iterating needs more time if you have more then one table. I need a function to change the row background by passing only the row index!
推荐答案
没有执行此任务的函数,但我们可以创建它,例如:
There is no function that performs this task, but we can create it, for example:
def setColortoRow(table, rowIndex, color):
for j in range(table.columnCount()):
table.item(rowIndex, j).setBackground(color)
这篇关于QTableWidget - 更改行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!