How to create sub item in the QTreeWidget?
I was able to create top level items (listing below), but still looking for sub items.
PyQt->5.6
Python->3.5
Spyder->3.0.2
import sys
from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QApplication, QWidget
if __name__ == '__main__':
app = 0
if QApplication.instance() != None:
app = QApplication.instance()
else:
app = QApplication(sys.argv)
l1 = QTreeWidgetItem([ "String A", "String B", "String C" ])
l2 = QTreeWidgetItem([ "String AA", "String BB", "String CC" ])
w = QWidget()
w.resize(510,210)
tw = QTreeWidget(w)
tw.resize(500,200)
tw.setColumnCount(3)
tw.setHeaderLabels(["Column 1", "Column 2", "Column 3"])
tw.addTopLevelItem(l1)
tw.addTopLevelItem(l2)
w.show()
app.exec_()
Use
{your QTreeWidgetItem}.addChild(child QTreeWidgetItem)
In my example: