Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QHeaderView::paintSection paints over widgets above?

    General and Desktop
    2
    3
    528
    Loading More Posts
    • 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.
    • qwasder85
      qwasder85 last edited by qwasder85

      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 Reply Quote 0
      • qwasder85
        qwasder85 last edited by

        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 Reply Quote 1
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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 Reply Quote 1
          • qwasder85
            qwasder85 last edited by

            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 Reply Quote 1
            • First post
              Last post