PDA

View Full Version : Prevent QStyledItemDelegate from drawing focus rectangle



stefanadelbert
15th July 2010, 03:32
I would like to prevent my derived QStyledItemDelegate from painting the focus rectangle.

I have achieved this before using a QItemDelegate by overriding its drawFocus function and doing nothing.

However QStyledItemDelegate does not implement drawFocus. Is there another way to prevent the QStyledItemDelegate from not painting the focus rectangle?

aamer4yu
15th July 2010, 06:56
In the paint function of your custom QStyledItemDelegate class -

QStyleOptionViewItem newOption = option;
newOption.state = option.state & (~QStyle::State_HasFocus);
QStyledItemDelegate::paint(painter,newOption,index );

stefanadelbert
15th July 2010, 09:26
Beautiful!

Thanks, aamer4yu.

Lykurg
15th July 2010, 09:40
Hi,

please also note our search function, because this question is asked every month...

But why I am replying is, because I wonder what is "better" or if there is a significant difference between
making a local copy of option as above
and
casting the const of option away?

aamer4yu
15th July 2010, 10:43
I wonder what is "better" or if there is a significant difference between
making a local copy of option as above
and
casting the const of option away?
I guess depends on habit too. I usually wont prefer to break something that wasn't meant to be broken.:rolleyes: