Results 1 to 4 of 4

Thread: QItemDelegates and currentItem

  1. #1
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Wink QItemDelegates and currentItem

    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:aint if painted item is current(current item have to be painted different than others).

    Thanks.
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QItemDelegates and currentItem

    Qt Code:
    1. // focus
    2. if (option.state & QStyle::State_HasFocus)
    3. {
    4. ...
    5. }
    6.  
    7. // selection
    8. if (option.state & QStyle::State_Selected)
    9. {
    10. ...
    11. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QItemDelegates and currentItem

    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.
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QItemDelegates and currentItem

    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
    Qt Code:
    1. QAbstractItemView* view = dynamic_cast<QAbstractItemView*>(parent());
    2. if (view && view->currentIndex() == index)
    3. option.state |= QStyle::State_HasFocus;
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.