Question

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?

Was it helpful?

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.

OTHER TIPS

If you are using a custom paintEvent(), you could place the characters manually with QPainter::DrawText(). Either print them one-by-one and increase the y coordinate of the output each time, or maybe try to utilize Qt::TextWordWrap flag to make them automatically wrap on spaces (you will need to make a really narrow bounding rectangle in this case I believe, I haven't tried it).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top