Results 1 to 1 of 1

Thread: Fixed: Delegate stops Model data background role color being painted

  1. #1
    Join Date
    Apr 2010
    Posts
    77
    Thanks
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Fixed: Delegate stops Model data background role color being painted

    Hi Guys

    I'm applying a delegate to a treeView but when I do it cancels out the background role of the data in the model represented by QModelIndex.
    If I get the QBrush value of the background role and then try the code below, it still doesn't fill in the background of the cell with the color.

    Can anyone tell me how to fix this?

    Thanks
    Jeff


    Qt Code:
    1. void JB_EntireTreeDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3.  
    4. QString currDescription = index.model()->data(index, Qt::DisplayRole).toString();
    5. QBrush backgroundBrush = index.model()->data(index, Qt::BackgroundRole).value<QBrush>();
    6.  
    7. QStyleOptionViewItem myOption = option;
    8. QString dataDescription = QString("%1 %2").arg(globalVal, currDescription);
    9. myOption.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
    10.  
    11. // none of these set the background color back to that of the index background role
    12. // myOption.palette.setBrush(QPalette::Window, backgroundBrush);
    13. // or
    14. // myOption.palette.setBrush(QPalette::Base, backgroundBrush);
    15. // or
    16. painter->setBackground(backgroundBrush);
    17.  
    18. drawDisplay(painter, myOption, myOption.rect, dataDescription);
    19. }
    To copy to clipboard, switch view to plain text mode 


    Added after 1 1:


    Fixed.

    I didn't realize I needed QItemDelegate drawbackground as well.

    Cheers
    Jeff
    Last edited by Jeffb; 3rd February 2012 at 02:07. Reason: Fixed it

Similar Threads

  1. Replies: 9
    Last Post: 14th February 2013, 19:39
  2. Combine custom delegate and model data() roles
    By qlands in forum Qt Programming
    Replies: 1
    Last Post: 4th October 2011, 12:43
  3. Qt delegate model data and view
    By giusepped in forum Qt Programming
    Replies: 0
    Last Post: 27th July 2011, 11:30
  4. Item Delegate editor background
    By LynneV in forum Qt Programming
    Replies: 2
    Last Post: 16th March 2010, 21:33
  5. How to populate delegate with model data.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 4th August 2008, 09:31

Tags for this Thread

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.