设置QTreeWidget头的文本的方法是什么? [英] What is the method to set the text for a QTreeWidget's header?

查看:1917
本文介绍了设置QTreeWidget头的文本的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了文档。



请注意,文档说它添加了一个新的列,因此如果您的视图已经有第0列,文本为1,您可以改为执行以下操作:

  if (QTreeWidgetItem * header = treeWidget-> headerItem()){
header-> setText(0,My Text);
} else {
treeWidget-> setHeaderLabel(My Text);
}


I've checked the documentation here and I can't seem to find a method for setting the text of a QTreeWidget's title or header.

Without setting the title QTreeWidget automatically uses the number '1' in my code. An example of what it looks like outputted is below. I'm presuming QTreeWidget has a method for this and I just can't find it.

解决方案

You're looking for setHeaderLabel.

Note that the documentation says it adds a new column, so if your view already has column 0 with text "1", you may instead have to do the following:

if(QTreeWidgetItem* header = treeWidget->headerItem()) {
  header->setText(0, "My Text");
} else {
  treeWidget->setHeaderLabel("My Text");
}

这篇关于设置QTreeWidget头的文本的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆