I want to represent a tree which has nodes that are/stay identical, but placed somewhere else:

Qt Code:
  1. -+- John
  2. '--+ Company A
  3. '----- Current Stockprice: 10
  4. -+- Jane
  5. '--+ Company A
  6. '----- Current Stockprice: 10
To copy to clipboard, switch view to plain text mode 
Say i want the "Company A" node with its children to be actually a single node.
Means it is identical also after updates (changes in one instance will affect all others). Its not an option to optimize it by reversing parent child hierarchy.

I tried it with a QStandardItem, but failed:

Qt Code:
  1. *simodel = new QStandardItemModel;
  2.  
  3. *root1 = new QStandardItem( "John" ),
  4. *root2 = new QStandardItem( "Jane" ),
  5. *leaf = new QStandardItem( "Company A" )
  6. ;
  7.  
  8. root1->appendRow( leaf );
  9. root2->appendRow( leaf );
  10.  
  11. simodel->invisibleRootItem()->appendRow( root1 );
  12. simodel->invisibleRootItem()->appendRow( root2 );
  13.  
  14. QTreeView *tview = new QTreeView;
  15. tview->setModel( simodel );
  16. tview->show();
  17.  
  18. return app.exec();
To copy to clipboard, switch view to plain text mode 

Gui shows:

Qt Code:
  1. -+- John
  2. '--+ Company A
  3. -+- Jane
  4. '--+ ~ <Some dead node which is not rendered>
To copy to clipboard, switch view to plain text mode 

Terminal output:
QStandardItem::insertRows: Ignoring duplicate insertion of item 0x9170758



Any hints whether this is doable with a QStandarditemModel or a custom QTreeView subclass ? The problem is remiscent of the Interview qtdemo, but I would need whole subtree's duplicated instead of single nodes.