简体   繁体   English

如何在QTreeWidget中更改默认的展开/折叠子项?

[英]How to change default expand/collapse sub-items in QTreeWidget?

I tried to create a simple treeview with the following code in Qt 4.8 我试图在Qt 4.8中使用以下代码创建一个简单的treeview

QTreeWidgetItem *city = new QTreeWidgetItem(ui->trvCompetitions);
city->setText(0, tr("City"));

(new QTreeWidgetItem(city))->setText(0, tr("Stockholm"));
(new QTreeWidgetItem(city))->setText(0, tr("Helsinki"));
(new QTreeWidgetItem(city))->setText(0, tr("Copenhagen"));

QTreeWidgetItem *other = new QTreeWidgetItem(ui->trvCompetitions);
other->setText(0, tr("Other"));

(new QTreeWidgetItem(other))->setText(0, tr("London"));
(new QTreeWidgetItem(other))->setText(0, tr("Tokio"));
(new QTreeWidgetItem(other))->setText(0, tr("Hanoi"));

And this is the treeview I got 这是我得到的树状视图

myTreeView

I have read this article and I only want my treeview has expand/collapse sub-items like that 我已经读过这篇文章 ,我只希望我的treeview具有这样的展开/折叠子项目

我想得到的TreeView

How can I change my treeview like this? 我该如何更改我的树状视图?

Thank! 谢谢!

After reading more documents about QTreeWidget, I realized that the treeview can be customized. 阅读有关QTreeWidget的更多文档后,我意识到可以自定义树视图。 I have modified my treeview following this post and the result was good as I desired. 我在这篇文章之后修改了我的treeview,结果如我所愿。

Change the number of columns. 更改列数。 Read documentation on that. 阅读有关文档。 Come back if you do not find out yourself. 如果您不了解自己,请回来。 I mostly use "the abstract way" with my own model. 我主要在自己的模型中使用“抽象方式”。

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

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