1

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!

Tan Viet
  • 1,983
  • 6
  • 25
  • 36
  • Could you clarify what exactly you want to achieve? It appears you already have subitems in your tree view. – dunc123 Aug 08 '13 at 11:30
  • 1
    @dunc123: I only want my treeview to have structure style (expand/collapse) like image 2 (Title column). – Tan Viet Aug 09 '13 at 02:27
  • I think the OP is looking to change the icons on the tree. As in, have the treeview use the boxed + and - icons instead of using triangles for the "expand the node" icon. – jrh Feb 10 '21 at 19:12

1 Answers1

1

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.

Tan Viet
  • 1,983
  • 6
  • 25
  • 36