title: PyQt5: How to generate a QTreeView from a list of dictionary items?
body: <p>I have a dataset like this:</p>
  
  <pre><code>[{'level': 0, 'dbID': 77, 'parent_ID': 6, 'short_name': '0:0:0:&lt;new&gt; to 6', 'long_name': '', 'order': 1, 'pos': 0} ,
  {'level': 1, 'dbID': 88, 'parent_ID': 77, 'short_name': '1:1:1:Store13', 'long_name': '', 'order': 2, 'pos': 1} ,
  {'level': 0, 'dbID': 442, 'parent_ID': 6, 'short_name': '2:&lt;new&gt;', 'long_name': '', 'order': 1, 'pos': 2} ,
  {'level': 1, 'dbID': 522, 'parent_ID': 442, 'short_name': '3:&lt;new&gt;', 'long_name': '', 'order': 2, 'pos': 3} ,
  {'level': 2, 'dbID': 171, 'parent_ID': 522, 'short_name': '3:&lt;new&gt;', 'long_name': '', 'order': 1, 'pos': 3} ,
  {'level': 0, 'dbID': 456, 'parent_ID': 6, 'short_name': '4:&lt;new&gt;', 'long_name': '', 'order': 1, 'pos': 4} ,
  {'level': 1, 'dbID': 523, 'parent_ID': 456, 'short_name': '5:&lt;new&gt;', 'long_name': '', 'order': 3, 'pos': 5}]
  </code></pre>
  
  <p>Here "level" means at which level of the tree the data will be. Level 0 means parent node, 1 means child of 0, 2 means child of 1 and so on. I have to generate a <code>QTreeView</code> from it. I have been trying in many different ways to do it, but I'm failing. Here's the code which I've written so far:</p>
  
  <p><strong>THE FUNCTION</strong>:</p>
  
  <pre><code>def populateTree(self):
      tree=self.structureData
      root_model=MoDaTreeModel()
      self.treeViewStructure.setModel(root_model)
      self.recursiveAdd(tree,0,root_model)
  
  def recursiveAdd(self,tree,n,parent):
      for i in range(n,len(tree)):            
          if(tree[i]['level']&lt;=tree[i+1]['level']):
              child_item=QStandardItem()
              child_item.setText(str(tree[i]['short_name']))
              parent.appendRow(child_item)
          else:
              self.recursiveAdd(tree,i+1) #I want to write the child node, but don't know how
  </code></pre>
  
  <p>Can someone help me as to how I can proceed from here?</p>