如何在 PyQt 中向 QTreeWidget 添加一行? 我遇到了一些严重的麻烦 - 我有一个 QString 列表,但我不知道如何将其添加到 QTreeWidget,它位于另一个类(类 Ui_Form)中,而 QStringList 位于另一个类中。
最佳答案
首先,您必须创建一个QTreeWidgetItem
列表,然后将它们添加到QTreeWidget中。
示例:
tree = your_qtreewidget # replace every 'tree' with your QTreeWidget
strings = list_of_strings
l = [] # list of QTreeWidgetItem to add
for i in strings:
l.append(QTreeWidgetItem(i)) # create QTreeWidgetItem's and append them
tree.addTopLevelItems(l) # add everything to the tree
引用文献:QTreeWidget和 QTreeWidgetItem在 PyQt 文档中。
关于python - 向 QTreeWidget 添加一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16770117/