Results 1 to 3 of 3

Thread: QStyledItemDelegate background color

  1. #1
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QStyledItemDelegate background color

    Hi all,
    Is it possible to know the background color in QStyledItemDelegate on this function ?
    Qt Code:
    1. void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
    To copy to clipboard, switch view to plain text mode 
    I would draw the item with a width less the icon size, the icon has transparent color around so the selection color or background of the widget has to be renderer on a rect.
    I know the size of the rect, I know how paint more little, only know the good color is missing.
    Is it possible to know the code needed ?
    Thanks for the help

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QStyledItemDelegate background color

    You can access the colour roles of the model index being drawn to get model's suggestion if any. The option parameter carries a palette member variable (QPalette) that gives the various style/system defined colours

  3. #3
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QStyledItemDelegate background color

    Works good, I tried QPalette since beginning but I used QPalette::Background which doesn't works, QPalette::Window has to be used :
    Qt Code:
    1. QBrush Background;
    2. if( ( itemOption.state & QStyle::State_Selected ) || ( itemOption.state & QStyle::State_MouseOver ) )
    3. Background = itemOption.palette.highlight();
    4. else
    5. Background = itemOption.palette.window();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Background color
    By FelixB in forum Qwt
    Replies: 4
    Last Post: 24th June 2013, 07:03
  2. How to set QPainter Background color?
    By marc2050 in forum Newbie
    Replies: 2
    Last Post: 29th April 2011, 05:29
  3. Replies: 0
    Last Post: 20th April 2011, 13:42
  4. Setting Background Color
    By SixDegrees in forum Qt Programming
    Replies: 5
    Last Post: 16th February 2011, 18:33
  5. Replies: 5
    Last Post: 30th March 2008, 16:53

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.