Prevent QStyledItemDelegate from drawing focus rectangle
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?
Re: Prevent QStyledItemDelegate from drawing focus rectangle
In the paint function of your custom QStyledItemDelegate class -
Code:
newOption.
state = option.
state & (~
QStyle::State_HasFocus);
QStyledItemDelegate::paint(painter,newOption,index);
Re: Prevent QStyledItemDelegate from drawing focus rectangle
Beautiful!
Thanks, aamer4yu.
Re: Prevent QStyledItemDelegate from drawing focus rectangle
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?
Re: Prevent QStyledItemDelegate from drawing focus rectangle
Quote:
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: