PDA

View Full Version : Question about subclassing QStyledItemDelegate



dpimka
10th July 2009, 16:08
Hi guys!

I have a subclass of QStyledItemDelegate and I want to reuse its decoration and selection painting, while painting text and other parts by myself.

I wonder how to achieve that.
I checked out QStyledItemDelegate's sources and found that it simply uses QStyle::drawControl() to draw CE_ItemViewItem.

Didn't find any way to use QStyle to draw selection (ordinary + hovered) only.

Any hints?

wysota
10th July 2009, 16:47
Make the text empty (QStyleOptionViewItemV4::text), call QStyle::drawControl() and then paint the text yourself.

dpimka
10th July 2009, 16:54
Oh, great. But what is the proper way to convert QStyleOptionViewItem to V4 format?

qobject_cast?

wysota
10th July 2009, 17:03
No, it's not a QObject. There is qstyleoption_cast or you can simply do:

QStyleOptionViewItemV4 opt(option); // assuming option is QStyleOptionViewItem

dpimka
10th July 2009, 17:09
Great. Thanks once more.