After reading http://doc.trolltech.com/4.3/model-view-view.html and http://doc.trolltech.com/4.3/model-view-delegate.html over and over again I still wonder how I am supposed to create my custom view. What I want is to take a tree-structure (I already have the model done) and show nodes in different ways.

I already did so by starting from QTreeView and reimplementing paintEvent() and going forward from there, just like QTreeView does with drawTree() until I realized I could use readily available widgets to display nodes instead. Say I want to use tabs to display nodes and QTextEdits (or any other widget) when editing information in them.

As an example, say I have a tree with a Root and it has 2 children, 1 QTextEdit and 1 QTabWidget. The QTabWidget has 2 children, both QTextEdits. The code for this is:

Qt Code:
  1. QWidget parent; //somehow defined
  2. //Root
  3. QTabWidget *qtabwidget = new QTabWidget(parent);
  4.  
  5. QWidget *qwidgetPage = new QWidget(qtabwidget);
  6. QVBoxLayout *qvboxlayoutPage = new QVBoxLayout(qwidgetPage);
  7. qvboxlayoutPage->setSpacing( 2 );
  8. qvboxlayoutPage->setMargin( 1 );
  9.  
  10. //Create and add children
  11. QTextEdit *qtextEdit = new QTextEdit(qwidgetPage);
  12. QTabWidget *qtabwidget2 = new QTabWidget(qwidgetPage);
  13. qvboxlayoutPage->addWidget(qtextEdit);
  14. qvboxlayoutPage->addWidget(qtabwidget2);
  15.  
  16. //Child1
  17. QWidget *qwidgetPage2 = new QWidget(qtabwidget);
  18. QVBoxLayout *qvboxlayoutPage2 = new QVBoxLayout(qwidgetPage2);
  19. qvboxlayoutPage2->setSpacing( 2 );
  20. qvboxlayoutPage2->setMargin( 1 );
  21. QTextEdit *qtextEdit2 = new QTextEdit(qwidgetPage2);
  22. qvboxlayoutPage2->addWidget(qtextEdit2);
  23.  
  24. //Child2
  25. QWidget *qwidgetPage2b = new QWidget(qwidgetPage2);
  26. QVBoxLayout *qvboxlayoutPage2b = new QVBoxLayout(qwidgetPage2b);
  27. qvboxlayoutPage2b->setSpacing( 2 );
  28. qvboxlayoutPage2b->setMargin( 1 );
  29. QTextEdit *qtextEdit3 = new QTextEdit(qwidgetPage2);
  30. qvboxlayoutPage2b->addWidget(qtextEdit3);
  31.  
  32.  
  33. qtabwidget->addTab( qwidgetPage, "Root");
  34. qtabwidget2->addTab( qwidgetPage2, "Node1");
  35. qtabwidget2->addTab( qwidgetPage2b, "Node2");
To copy to clipboard, switch view to plain text mode 

Where am I supposed to do this? I can't do it in the paintEvent() for sure.

I just cannot find the function from where I can start creating these widgets to create my own view. The tree is defined in the model so the function I'm looking for is loaded after setModel has been called.

Could it possibly be that I should use QItemDelegate for this - I still have problems understanding how and when they are supposed to be used. If so, how? Any guides available online?