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. QHeaderView::paintSection paints over widgets above?

QHeaderView::paintSection paints over widgets above?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 990 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.
  • qwasder85Q Offline
    qwasder85Q Offline
    qwasder85
    wrote on last edited by qwasder85
    #1

    I have a QTreeView that features a frozen column like explained in http://doc.qt.io/qt-5/qtwidgets-itemviews-frozencolumn-example.html. Basically, a second QTreeView stacked above a base QTreeView and only showing one column.

    The problem comes when I have to handle painting of the base QTreeView's QHeaderView myself (for a requested feature). When implementing QHeaderView::paintSection, it ends up painting over the overlying, frozen header. When I scroll the view now, it draws over the would-be frozen header.

    Blue: "frozen" QTreeView, Yellow: base QTreeView drawing its header over the frozen view's headers above.
    Blue: "frozen" QTreeView, Yellow: base QTreeView drawing its header over the frozen view's headers.

    Here's my paintSection:

    void FrozenTreeWidget::MySpecialHeaderView::paintSection( QPainter* in_p_painter, const QRect& in_rect, int in_section ) const
    {
        in_p_painter->save();
        QHeaderView::paintSection( in_p_painter, in_rect, in_section );
        in_p_painter->restore();
    
        // Paint something else on the column sections
        QRect my_rect( in_rect.right(), in_rect.top(), 1, in_rect.height() );
        in_p_painter->fillRect( my_rect, QColor( "green" ) );
    }
    

    In my FrozenTreeWidget, I then assign it as the base view's header:

    MySpecialHeaderView* p_header = new MySpecialHeaderView( Qt::Horizontal, this );
    setHeader( p_header );
    

    I'm really stumped with this one.

    1 Reply Last reply
    0
    • qwasder85Q Offline
      qwasder85Q Offline
      qwasder85
      wrote on last edited by
      #3

      Alright, while constructing a compilable sample, I figured it out:
      I missed calling "stackUnder()" on my special header class and stacking it under the frozen table view.
      Just making the base table its parent, or stacking it under the frozen table's header does not work.

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

        Hi,

        Can you provide a minimal compilable example that shows that behaviour ?

        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
        1
        • qwasder85Q Offline
          qwasder85Q Offline
          qwasder85
          wrote on last edited by
          #3

          Alright, while constructing a compilable sample, I figured it out:
          I missed calling "stackUnder()" on my special header class and stacking it under the frozen table view.
          Just making the base table its parent, or stacking it under the frozen table's header does not work.

          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