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.
The
QItemDelegate.paint
method accepts aQStyleOptionViewItem
as a parameter, which is inherited fromQStyleOption
.QStyleOption
has a member variable namedstate
of typeQStyle::State
. One of the possible bit flags for state isQStyle::State_Selected
, which is what you want to test for.