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. QTreeView: change background color of specific column header
Forum Updated to NodeBB v4.3 + New Features

QTreeView: change background color of specific column header

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.4k Views 1 Watching
  • 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.
  • sitesvS Offline
    sitesvS Offline
    sitesv
    wrote on last edited by
    #1

    Is it possible to change the background color of a specific column of QTreeView header?

    This can change the background color of all columns:

    ui->tree->setStyleSheet("QHeaderView::section { background-color:red }");
    

    This is not working:

    ui->tree->model()->setHeaderData(col, Qt::Horizontal, QBrush(QColor("red")), Qt::BackgroundRole);
    

    Is there any ideas?

    Thank you!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The style used to draw your application is free to ignore certain hints to follow the OS style they represent. That's why your second line may have no effect.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • sitesvS Offline
        sitesvS Offline
        sitesv
        wrote on last edited by
        #3

        I tried to use default and Fusion styles:

        QApplication::setStyle(QStyleFactory::create("Fusion"));
        

        Style was changed.

        The header cell is empty for both styles as a result.
        2.png

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Please provide a minimal compilable example that reproduces this.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • sitesvS Offline
            sitesvS Offline
            sitesv
            wrote on last edited by
            #5

            Hi!
            Problem solved by redefinition of QHeaderView::paintSection.
            Thank you!

            1 Reply Last reply
            1

            • Login

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