Results 1 to 6 of 6

Thread: QHeaderview and backgroundColorRole

  1. #1
    Join Date
    May 2011
    Posts
    20
    Thanked 3 Times in 3 Posts
    Platforms
    Unix/X11

    Default QHeaderview and backgroundColorRole

    I have a table view and I need a way to set the color of a row header for a particular row. Note that some row headers may have different colors. In my model in the headerData() function I handle the case of QBackgroundRole and QBackgrounColorRole. Neither of them do anything. How do you specify the color of a row header?

    Thanks.

  2. The following user says thank you to snydesc for this useful post:


  3. #2
    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: QHeaderview and backgroundColorRole

    QHeaderView does not respect BackgroundRole. If you want to color a header, you have to do that yourself by reimplementing the header section drawing routine.
    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.


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


  5. #3
    Join Date
    May 2011
    Posts
    20
    Thanked 3 Times in 3 Posts
    Platforms
    Unix/X11

    Default Re: QHeaderview and backgroundColorRole

    But the documentation says: QHeaderView respects the following item data roles: TextAlignmentRole, DisplayRole, FontRole, DecorationRole, ForegroundRole, and BackgroundRole.

  6. The following user says thank you to snydesc for this useful post:


  7. #4
    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: QHeaderview and backgroundColorRole

    Hmm.... indeed. In that case please provide a minimal compilable example reproducing the problem.
    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.


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


  9. #5
    Join Date
    May 2011
    Posts
    20
    Thanked 3 Times in 3 Posts
    Platforms
    Unix/X11

    Default Re: QHeaderview and backgroundColorRole

    OK I found out what is happening. There was a style being applied to QHeaderView::section. Apparently if you apply a style you can't override it within the model. This is problematic as I would would like all rows to be styled the same color and then have the model determine if the row colors should change. Any ideas?

  10. The following user says thank you to snydesc for this useful post:


  11. #6
    Join Date
    Jun 2012
    Posts
    8
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: QHeaderview and backgroundColorRole

    I am facing the same Problem right now - I would like to have a verticalHeader with alternatingRowcolors, while you can set this option to true it does not work and there seems to be no way to set the backgroundcolor for specific HeaderItems - no one has an Idea, or maybe you have solved the problem by now?

  12. The following user says thank you to bisasatan for this useful post:


Similar Threads

  1. QStyle vs Qt::BackgroundColorRole
    By wirasto in forum Qt Programming
    Replies: 4
    Last Post: 10th April 2015, 16:23
  2. Same QHeaderView for several tables
    By qks1 in forum Newbie
    Replies: 4
    Last Post: 21st November 2012, 13:28
  3. Replies: 0
    Last Post: 20th January 2010, 20:51
  4. QHeaderView
    By waynew in forum Qt Programming
    Replies: 2
    Last Post: 25th December 2009, 21:42
  5. QHeaderView
    By gyre in forum Qt Tools
    Replies: 1
    Last Post: 25th September 2007, 17:35

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.