How do I determine if the item is selected or not in the paint() function of QItemDelegate?

StackOverflow https://stackoverflow.com/questions/1711104

  •  19-09-2019
  •  | 
  •  

Question

I am making a table using QItemDelegate. I use the paint(..) method to draw delegated items to look the same when they go out of edit mode but I also need to draw the items differently when they are selected or not and the paint method is also called during those events. My question is how do I know when to draw which?

thank you.

Was it helpful?

Solution

The QItemDelegate.paint method accepts a QStyleOptionViewItem as a parameter, which is inherited from QStyleOption. QStyleOption has a member variable named state of type QStyle::State. One of the possible bit flags for state is QStyle::State_Selected, which is what you want to test for.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top