简体   繁体   English

PyQt:如何在QTreeWidget中扩展所有子级

[英]PyQt: How to expand all children in a QTreeWidget

There is no real problem, I have just a cosmetic problem. 没有真正的问题,我只是一个表面问题。 Well, first I create a form with Qt Designer. 好吧,首先我用Qt Designer创建一个表单。 On this form I place a QTreeWidget . 在此表单上,我放置了一个QTreeWidget We are still in Qt Designer. 我们仍然在Qt Designer中。 In QTreeWidget , I make a few entries (parents), and then I also take a few child entries. QTreeWidget ,我进行了一些输入(父项),然后还进行了一些子项输入。 When I am done, I save the ui-file and then I load this file - using loadUi() dynamically. 完成后,保存ui文件,然后加载该文件-动态使用loadUi() In this case I use PyQt4. 在这种情况下,我使用PyQt4。 Up to this point no problem. 至此没有问题。

When I load the form with placed QTreeWidget I want the program to expand all child entries . 当我使用放置的QTreeWidget加载表单时, 我希望程序扩展所有子项 By default, when I run the program I only see the parent entries. 默认情况下,运行程序时,我只会看到父项。 When I want to see the child entries I have to click on the parent entries, but I don't want this. 当我想查看子条目时,我必须单击父条目,但是我不希望这样。

Is there a way to solve this? 有办法解决吗?

There is an expandAll() method, which QTreeWidget inherits from the QTreeView class. 有一个expandAll()方法, QTreeWidget继承自QTreeView类。 So, after calling loadUi() , just add something like this: 因此,在调用loadUi() ,只需添加如下内容:

  self.treewWidget.expandAll()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM