Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
devwiki:python_qt [2019/06/10 03:07]
ying [Dialog]
devwiki:python_qt [2019/06/13 02:04] (current)
ying [Tree Widget]
Line 1274: Line 1274:
             cur_tree.editItem(item,​ col)             cur_tree.editItem(item,​ col)
 </​code>​ </​code>​
-  * expand ​top nodes <code python>+  * expand ​tree <code python>
 # expand top node # expand top node
 for i in range(cur_tree.topLevelItemCount()):​ for i in range(cur_tree.topLevelItemCount()):​
     cur_tree.topLevelItem(i).setExpanded(1)     cur_tree.topLevelItem(i).setExpanded(1)
 +    ​
 +# expand all
 +cur_tree.expandAll()
 +
 +# expand to depth for tree view only
 +cur_tree.expandToDepth(1)
 +
 +# use this code to expand to level
 +    def tree_expand(self,​ node, level=0):
 +        if isinstance(node,​ (str, unicode)):
 +            node = self.uiList[node].invisibleRootItem()
 +        # expand top node
 +        for i in range(node.childCount()):​
 +            node.child(i).setExpanded(1)
 +            # sub node
 +            if level == -1:
 +                self.tree_expand(node.child(i),​ level)
 +            elif level > 0:
 +                level -=1
 +                self.tree_expand(node.child(i),​ level)
 </​code>​ </​code>​
   * common tree quick creation function<​code python>   * common tree quick creation function<​code python>