简体   繁体   中英

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

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

How can I change my treeview like this?

Thank!

After reading more documents about QTreeWidget, I realized that the treeview can be customized. I have modified my treeview following this post and the result was good as I desired.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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