Tan Viet
Tan Viet

Reputation: 2113

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

The TreeView I want to get

How can I change my treeview like this?

Thank!

Upvotes: 1

Views: 2632

Answers (1)

Tan Viet
Tan Viet

Reputation: 2113

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.

Upvotes: 1

Related Questions