QHeaderView::paintSection paints over widgets above?
-
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.
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.
-
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. -
Hi,
Can you provide a minimal compilable example that shows that behaviour ?
-
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.