QTableWidget - Change the row color

故事扮演 提交于 2020-01-29 18:29:29

问题


I'm trying to change the color of background of an QTableWidget. There is some others posts about the same things bot nothing of the given solution worked for me.

  • With that solution, we are setting the background on an alredy existed item in the table to a light grey on the item a 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 need more time if you have more then one table. I need a function to change the row background by passing only the row index!


回答1:


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)



来源:https://stackoverflow.com/questions/43512041/qtablewidget-change-the-row-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!