Results 1 to 4 of 4

Thread: Custom Item Delegate Reset, sort of.

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Custom Item Delegate Reset, sort of.

    After you set a custom item delegate on a view row, how can you 'unset' it?
    So the view row gets repainted according to say, the style sheet applied to it.

    For example, if the style sheet colors the row brown and then the custom item delegate colors the row green, and your data changes so you want the row brown again, how do you do this?

    Applying the custom item delegate works fine, but when the data changes and I need to re-color the row according to the style sheet, I don't see how to do it.

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Custom Item Delegate Reset, sort of.

    Just assign a new delegate to the row. For the default delegate use:
    Qt Code:
    1. QAbstractItemView::setItemDelegateForRow(int, QAbstractItemView::delegate());
    To copy to clipboard, switch view to plain text mode 
    Don't know whether this will help or not, but I color cells in a view by testing in the paint method of a custom delegate. By using QModelIndex::sibling() you can color an entire row. Attached is an app that demonstrates this using the sqlite db "person" from the Qt examples. It colors rows with odd number ids. Try changing some of the ids.
    Attached Files Attached Files

  3. The following user says thank you to norobro for this useful post:

    waynew (1st September 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom Item Delegate Reset, sort of.

    You can always derive your custom delegate from QStyledItemDelegate and when you don't need the extra functionality, just disable it in your delegate and call the base class implementation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    waynew (1st September 2010)

  6. #4
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom Item Delegate Reset, sort of.

    Thanks for the help folks and the example Norobro. This is very cool. I would probably have never figured out you could do that.
    Qt is really amazing.
    Got the basics working fine, just need to do a little code cleanup and it's done.

Similar Threads

  1. Replies: 19
    Last Post: 25th November 2010, 08:52
  2. QTreeWidget Custom Item Delegate
    By photo_tom in forum Qt Programming
    Replies: 1
    Last Post: 20th May 2010, 18:59
  3. Replies: 5
    Last Post: 10th August 2009, 10:50
  4. QMovie from inside a custom item delegate
    By Crazy_Hopper in forum Qt Programming
    Replies: 3
    Last Post: 7th May 2008, 15:18
  5. [Qt4] Noob and custom Item Delegate
    By naresh in forum Newbie
    Replies: 36
    Last Post: 19th March 2006, 15:46

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.