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
Forum Updated to NodeBB v4.3 + New Features

Background color of headers doesn't change in QAbstractTableModel

Scheduled Pinned Locked Moved Solved General and Desktop
tableview
2 Posts 2 Posters 360 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 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?

    Christian EhrlicherC 1 Reply Last reply
    0
    • L leonardo M B

      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?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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

      • Login

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