Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Background color of headers doesn't change in QAbstractTableModel

Background color of headers doesn't change in QAbstractTableModel

Scheduled Pinned Locked Moved Solved General and Desktop
tableview
2 Posts 2 Posters 346 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leonardo M B
    wrote on 3 Apr 2023, 15:22 last edited by
    #1

    So I Have this code and basically I would like to change the color of each section based on some property, but this doesn't work.

    QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const
    {
      if (role == Qt::BackgroundRole && *somecondition*) {
        return QBrush(CHANGECOLOR);
      }
    

    Any Idea?

    C 1 Reply Last reply 3 Apr 2023, 16:47
    0
    • L leonardo M B
      3 Apr 2023, 15:22

      So I Have this code and basically I would like to change the color of each section based on some property, but this doesn't work.

      QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const
      {
        if (role == Qt::BackgroundRole && *somecondition*) {
          return QBrush(CHANGECOLOR);
        }
      

      Any Idea?

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 3 Apr 2023, 16:47 last edited by
      #2

      I think it's a style issue as explained here: https://doc.qt.io/qt-6/stylesheet.html
      "For example, it might be tempting to set the QPalette::Button role to red for a QPushButton to obtain a red push button. However, this wasn't guaranteed to work for all styles, because style authors are restricted by the different platforms' guidelines and (on Windows and macOS) by the native theme engine."

      Which OS & Qt style do you use?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • L leonardo M B has marked this topic as solved on 6 Apr 2023, 16:40

      1/2

      3 Apr 2023, 15:22

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved