import sys, os, pprint, time
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
app = QApplication(sys.argv)
view = QTreeView()
view.setSelectionBehavior(QAbstractItemView.SelectRows)
model = QStandardItemModel()
model.setHorizontalHeaderLabels(['col1', 'col2', 'col3'])
view.setModel(model)
view.setUniformRowHeights(True)
for i in range(5):
parent1 = QStandardItem('Family {}. Some long status text for sp'.format(i))
for j in range(3):
child1 = QStandardItem('Child {}'.format(i*3+j))
child2 = QStandardItem('row: {}, col: {}'.format(i, j+1))
child3 = QStandardItem('row: {}, col: {}'.format(i, j+2))
parent1.appendRow([child1, child2, child3])
model.appendRow(parent1)
view.setFirstColumnSpanned(i, view.rootIndex(), True)
index = model.indexFromItem(parent1)
view.expand(index)
selmod = view.selectionModel()
index2 = model.indexFromItem(child3)
selmod.select(index2, QItemSelectionModel.Select | QItemSelectionModel.Rows)
view.show()
sys.exit(app.exec_())
import sys, os, pprint, time
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
view = QTreeView()
view.setSelectionBehavior(QAbstractItemView.SelectRows)
model = QStandardItemModel()
model.setHorizontalHeaderLabels(['nameSpace:col1'])
view.setModel(model)
view.setUniformRowHeights(True)
parent1 = QStandardItem(u'第一行')
child1 = QStandardItem(u'第二层')
parent1.appendRow([child1])
chi1 = QStandardItem(u'第三层1')
chi2 = QStandardItem(u'第三层2')
child1.appendRow([chi2])
child1.appendRow([chi2])
child1.appendRow([chi1])
model.appendRow(parent1)
view.show()