0

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?

Arnab Datta
  • 5,356
  • 10
  • 41
  • 67

2 Answers2

0

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.

Matthew
  • 2,759
  • 18
  • 28
  • how would I install a custom QHeaderView-derived class to be my horizontal header? At the moment I am setting headerLabels by using `QTreeWidget::setHeaderLabels(QStringList labels)` – Arnab Datta Jul 30 '12 at 14:05
  • Inside the constructor of your `QTreeWidget`-derived class do this, `setHeader( new MyCustomHeader( Qt::Horizontal, this ) );` – Matthew Jul 30 '12 at 14:07
  • this is a good suggestion and it works, but I actually used a QStyle to solve my problem. – Arnab Datta Jul 31 '12 at 12:39
0

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).

SingerOfTheFall
  • 29,228
  • 8
  • 68
  • 105