Search code examples
c++qtqtreewidgetqtguiqheaderview

vertical header labels in QTreeWidget


I have a QTreeWidget with horizontal header labels at the moment and my intention is to draw only the headerLabels vertically and the rest horizontally.

I don't want to reimplement everything in QTreeWidgets's paintEvent method, so I am thinking of controlling the paintevent for the header labels, and then calling the superclass paintevent.

Something along the lines of this:

class MyTreeWidget: public QTreeWidget
{
  public void paintEvent (QPaintEvent *e)
  {
      ..... //Draw header labels vertically
      QTreeWidget::paintEvent(e);
  }
}

I've tried inserting a \n after each character when inserting headerLabels, but that's a really ugly hack and something I don't really want to do.

My problem is that I don't really know how to get a hold of the header items or how to paint them vertically. Any ideas?


Solution

  • I believe you want to create a QHeaderView-derived class, where you change the default implementation for paintEvent( QPaintEvent* );

    and then install your custom QHeaderView-derived class as your horizontal header for your MyTreeWidget class.