Hello to everybody,
I need help to set the background colour of rows of a power table object, based on the value of a specified coloumn.
I.e. if the value of the second coloumn of my power table is 1 I need to set the background colour of that row red, if the value is 10 the corrispondent row shoud be green.
So, why then when I use the above solution for coloring the rows based on a cell value, do the colors not follow the correct rows when the table is sorted?
Without seeing what you have done, itâs difficult to say.
That said, one thing may be to ensure you have a default config for your cell. For example:
value = self.data.getValueAt(rowIndex,"columnName"))
if value >= 0 and value <= 90 :
return{'background': '#FF0100'}
if value >= 91 and value <=120 :
return{'background': 'yellow'}
return{'background': 'green'} # default config
Also, note that there are two different row indices you get in configureCell- rowIndex and rowView; your code may be using the wrong index or retrieving values from the âwrongâ dataset (viewDataset vs data).
However, I donât quite understand why rowIndex is the correct argument instead of rowView. The docstring for rowView says â(affected by sorting)â which leads me to believe that I should be using rowView.
It depends on what youâre doing. If youâre retrieving values from the viewDataset property of the table, you should be using rowView. If youâre retrieving values from the data property, you should be using rowIndex.
Another tweak, just in case someone else wants to do this:
This will highlight the full row where the value in column x in the backing dataset changes vs the row above.
Currently sets even rows to yellow and odd to orange.
Column_I_Want_to_Monitor = 5
#Defines what column will be configured
#if colIndex == Column_I_Want_to_Monitor and rowIndex > 0:
if rowIndex > 0:
#Checks if the column is the right one and that it's not the first row
#previousCellValue = self.data.getValueAt(rowIndex-1,colIndex)
previousCellValue = self.data.getValueAt(rowIndex-1,Column_I_Want_to_Monitor)
currentRowValue=self.data.getValueAt(rowIndex,Column_I_Want_to_Monitor)
#On the Power Chart's dataset, finds the value at the previous cell
#if previousCellValue != textValue:
if previousCellValue != currentRowValue:
if rowIndex % 2 ==0:
return {'background': 'yellow'}
else:
return {'background': 'orange'}
I still don't understanding why rowView is not affected by sorting when retrieving values from data property... Also, the rowIndex is affected by sorting too but the only difference is it's not written in its description?
The rowIndex is the position of the row as it exists in the table's dataset property. The rowView is the position of the row as it is observed by the user in the table itself.