简体   繁体   English

QTreeWidget中的垂直标题标签

[英]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. 我现在有一个带有水平标题标签的QTreeWidget,我的意图是垂直绘制headerLabel,其余水平绘制。

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 . 我不想在QTreeWidgets的paintEvent方法中重新实现所有功能,因此我正在考虑控制标题标签的paintevent,然后调用超类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. 在插入headerLabels时,我曾尝试在每个字符后插入\\n ,但这是一个非常丑陋的技巧,而我确实不想做。

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? 有任何想法吗?

I believe you want to create a QHeaderView -derived class, where you change the default implementation for paintEvent( QPaintEvent* ); 我相信您想创建一个QHeaderView派生的类,在其中您更改paintEvent( QPaintEvent* );的默认实现paintEvent( QPaintEvent* );

and then install your custom QHeaderView -derived class as your horizontal header for your MyTreeWidget class. 然后安装您的自定义QHeaderView派生类作为你的水平头MyTreeWidget类。

If you are using a custom paintEvent() , you could place the characters manually with QPainter::DrawText() . 如果使用自定义paintEvent() ,则可以使用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). 要么一次打印它们,然后每次增加输出的y坐标,要么尝试利用Qt::TextWordWrap标志使它们自动换行(在这种情况下,您需要制作一个非常狭窄的边界矩形)我相信,我还没有尝试过)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM