title: How to insert child into QTreeWidget hierarchy?
body: <p>Consider I have QTreeWidget with following items hierarchy:</p>
  
  <pre><code>top_item
    |--child
  </code></pre>
  
  <p>Every item has assigned with <code>setItemWidget()</code> widget.
  I need to insert another child between my first two elements like this :</p>
  
  <pre><code>top_item
    |--another_child
       |--child
  </code></pre>
  
  <p>I trying to do that with following code:</p>
  
  <pre><code>QTreeWidgetItem* top_item = new QTreeWidgetItem;
  ui-&gt;treeWidget-&gt;addTopLevelItem(top_item);
  QTreeWidgetItem* child_item = new QTreeWidgetItem;
  top_item-&gt;addChild(child_item);
  
  ui-&gt;treeWidget-&gt;setItemWidget(top_item, 0, new QPushButton);
  ui-&gt;treeWidget-&gt;setItemWidget(child_item, 0, new QPushButton);
  
  // ---- let's insert another child ----
  auto last_children = top_item-&gt;takeChildren();
  
  QTreeWidgetItem* another_child_item = new QTreeWidgetItem;
  top_item-&gt;insertChild(0, another_child_item);
  ui-&gt;treeWidget-&gt;setItemWidget(another_child_item, 0, new QPushButton);
  
  another_child_item-&gt;addChildren(last_children);
  </code></pre>
  
  <p>It works fine except one moment — it lost assigned widgets.
  I've tried to take and save the widgets before taking children with</p>
  
  <pre><code>QWidget* widget_from_child_item = ui-&gt;treeWidget-&gt;itemWidget(child_item, 0);
  ui-&gt;treeWidget-&gt;removeItemWidget(child_item, 0);
  </code></pre>
  
  <p>but after calling <code>takeChildren()</code> all assigned widgets have been deleted and app is crashing after reassigning the widgets with <code>setItemWidget()</code>.</p>
  
  <p>What is my mistake?</p>