Hello!

This is my first time using a tree widget. I managed to put it together using QTreeWidget and QTreeWidgetItem. In the first column of every item I have a checkbox and in the second colum there is a QString. I want the string to be flushed left to the checkbox on every level, but it doesn't work. If I open the tree deep enough, upper levels resize and create a gap between the checkbox and the text. The attached picture illustrates the problem.

treeview.png

Here is how I create it:

Qt Code:
  1. QTreeWidget *treeWidget = new QTreeWidget(this);
  2. treeWidget->setColumnCount(2);
  3. //treeWidget->header()->hide();
  4. treeWidget->header()->setResizeMode(0, QHeaderView::ResizeToContents);
  5. treeWidget->setAnimated(true);
  6. treeWidget->setSelectionMode(QTreeWidget::NoSelection);
  7. treeWidget->setFocusPolicy(Qt::NoFocus);
  8. QList<QTreeWidgetItem*> items;
  9. for (int i = 0; i < 3; ++i)
  10. {
  11. ti->setText(0, QString("item: %1").arg(i));
  12.  
  13. for (int j = 0; j < 3; ++j)
  14. {
  15. ti2->setCheckState(0, Qt::Unchecked);
  16. ti2->setText(1, QString("item: %1").arg(j));
  17.  
  18. for (int k = 0; k < 3; ++k)
  19. {
  20. ti3->setCheckState(0, Qt::Unchecked);
  21. ti3->setText(1, QString("item: %1").arg(k));
  22. ti2->addChild(ti3);
  23. }
  24.  
  25. ti->addChild(ti2);
  26. }
  27.  
  28. items.append(ti);
  29. }
  30. treeWidget->insertTopLevelItems(0, items);
To copy to clipboard, switch view to plain text mode 


How can I fix this?

And while we are at it, I would prefer to have this Windows Explorer style with the plus button, as can be seen in the simple tree model example. How can I get that?