PDA

View Full Version : QItemDelegates and currentItem



mchara
22nd January 2008, 14:39
Hi all,
i'd like to ask one thing...
does anyone knows is there any possibility to check in QItemDelegate is draw item current one in tree/list/view/etc. or not.

The thing is that i have a tree that draws a button per cell(not itemWidget, but overriden paint event that redraws whole tree with stylepainter) but i'm doing lots of unnecessary updates(buttons looks differently when clicked, when mouse is over, when they are selected or when they are current).
Using QItemDelegates would increase performance heavily ( i'm painting whole visible tree area everytime because of some implementation difficulties in paint event) but i'm searching qt manuals whole day and i can't find a method to check in QItemDelegate::paint if painted item is current(current item have to be painted different than others).

Thanks.

jpn
22nd January 2008, 14:56
// focus
if (option.state & QStyle::State_HasFocus)
{
...
}

// selection
if (option.state & QStyle::State_Selected)
{
...
}

mchara
23rd January 2008, 06:37
Tried, but Has_Focus is set only when item is current and view has focus and i need to draw current item different even if view have no focus so this state is rather useless.
Any other ideas?

I thought about setting ModelIndex in delegate when current changes but it doesn't fits to typical delegates usage and i'm not sure if i want to implement such workarounds.

jpn
23rd January 2008, 06:52
I'd suggest using QPersistentModelIndex if you decide to store an index. An ugly but quite common workaround to deliver information from view to delegate is to assume that the view is parent of the delegate. This way you can also easily check if


QAbstractItemView* view = dynamic_cast<QAbstractItemView*>(parent());
if (view && view->currentIndex() == index)
option.state |= QStyle::State_HasFocus;