views:

89

answers:

1

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.

+2  A: 

The 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.

Caleb Huitt - cjhuitt
thx a whole lot, I knew it was that object but couldn't find where. I have another question you might be able to answer: my special view in my table is actually a QPushButton. I am wondering if you know how I could make it change text when I click on it and and at the same time make text from other columns change values also.
yan bellavance
@yan: I don't know of a simple way to do that. The complicated way would be to use the model index given to the delegate, use that to get the model, and somehow notify the model to change some value it has for the data to return. Then return different data for each row in that column from your model.
Caleb Huitt - cjhuitt