Results 1 to 6 of 6

Thread: QTableView headerData() color

  1. #1
    Join Date
    Mar 2008
    Posts
    29
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QTableView headerData() color

    Good morning all,
    does anyone know, how to color the QTableViews header by using the standard delegate in Qts MV architecture? I tried this by using the roles as it does in the data() method, but in the headerData() nothing happens :-(

    Qt Code:
    1. QVariant SchulungsplanModel::headerData(int section, Qt::Orientation orientation, int role) const
    2. {
    3. // HORIZONTAL HEADER: (timeline)
    4. if (orientation == Qt::Horizontal)
    5. {
    6. if(role == Qt::BackgroundRole)
    7. return QVariant(QBrush(QColor(Qt::green), Qt::SolidPattern));
    8.  
    9. if(role == Qt::DisplayRole)
    10. {
    11. if (section < m_horizontalHeaderList.size())
    12. return m_horizontalHeaderList.at(section);
    13. }
    14. }
    15.  
    16. // VERTICAL HEADER: PUs
    17. if (orientation == Qt::Vertical)
    18. {
    19. if(role == Qt::DisplayRole)
    20. {
    21. if (section < m_verticalHeaderList.size())
    22. return m_verticalHeaderList.at(section);
    23. }
    24. }
    25.  
    26. return QAbstractTableModel::headerData(section, orientation, role);
    27. }
    To copy to clipboard, switch view to plain text mode 

  2. #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: QTableView headerData() color

    The header doesn't use the delegate. It's a very limited class, so if you want something fancy, you'll have to subclass QHeaderView and implement it yourself.

  3. #3
    Join Date
    Mar 2008
    Posts
    29
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView headerData() color

    Hi,
    it is unbelievable, I compiled my project on Unix (HP-UX) and it worked !!!

    It seems to be, that I detected a Qt bug ?!??
    On Windows the roles statements doesn't work !

    Do you have any idea ?

  4. #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: QTableView headerData() color

    Qt tries to follow the platform style. If Windows doesn't allow header colours to be modified, they won't be. You could run your application with a different style (using -style stylename switch, i.e. -style plastique) on Windows and it'll probably work then.

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

    starcontrol (16th April 2008)

  6. #5
    Join Date
    Mar 2008
    Posts
    29
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView headerData() color

    this is the cheat ;-)

    with a different style it works ! oh, oh, ....
    and all the other roles are also supported ;-) foreground etc...

  7. #6
    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: QTableView headerData() color

    You can "cheat" even more by changing the style of the header only and leaving the rest of the application running the default style. That's how stylesheets work, by the way...

Similar Threads

  1. how to color a cell in a QTableView
    By JeanC in forum Qt Programming
    Replies: 13
    Last Post: 9th September 2015, 10:08
  2. Using a QFrame as a color selection indicator
    By KShots in forum Qt Tools
    Replies: 8
    Last Post: 14th June 2011, 23:55
  3. QTableView change color of current Cell
    By raphaelf in forum Qt Programming
    Replies: 4
    Last Post: 4th March 2006, 11:22

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.