Home > Enterprise >  How to read the background color of selected row in tableview?
How to read the background color of selected row in tableview?

Time:11-24

This is how i get the value of a selected cell:

self.value = index.sibling(index.row(), 1).data()

But how can i read the color of that selected row/cell that i have set previously while adding the item like this:

model.setData(model.index(row, 0), QBrush(Qt.yellow), Qt.BackgroundRole)

I need: if selected row is yellow: do something...

Thank you

CodePudding user response:

The default argument of data() is the DisplayRole, so if you need to retrieve another role you have to specify it:

self.value = index.sibling(index.row(), 1).data(Qt.BackgroundRole)
  • Related