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. How Paint a background section in a QHeaderView?

How Paint a background section in a QHeaderView?

Scheduled Pinned Locked Moved Solved General and Desktop
qheaderview
2 Posts 2 Posters 369 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 leonardo M B
    #1

    So I was trying to color the background of certain cells based on the data on them, will implement the logic later. The problem Now Is that in the code below fillrect paints everything and erases the text of the header section. How Can I paint the text and the background color?

    void ResizableVerticalHeader::paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const
    {
      painter->save();
      QHeaderView::paintSection(painter, rect, logicalIndex);
      painter->restore();
      painter->fillRect(rect, QBrush(QColor(0xE1, 0xFF, 0x3C)));
    }
    
    Christian EhrlicherC 1 Reply Last reply
    0
    • L leonardo M B

      So I was trying to color the background of certain cells based on the data on them, will implement the logic later. The problem Now Is that in the code below fillrect paints everything and erases the text of the header section. How Can I paint the text and the background color?

      void ResizableVerticalHeader::paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const
      {
        painter->save();
        QHeaderView::paintSection(painter, rect, logicalIndex);
        painter->restore();
        painter->fillRect(rect, QBrush(QColor(0xE1, 0xFF, 0x3C)));
      }
      
      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      Since you don't call the base class impl - what do you expect?

      Overrride initStyleOption() and set the desired color for QPalette::Window or even better override initStyleOptionForIndex()

      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
      1
      • L leonardo M B has marked this topic as solved on
      • rudagR rudag referenced this topic on

      • Login

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