tree views使用一个tree结构的model,因此遍历所有model的items的最容易的方法是使用一个递归程序,就像我们队tree widgets操作的那样,下面是例子:
Example 6.12 The tst_treeview Test Script
def checkAnItem(indent, index, treeView, model, selectionModel):
if indent>-1 and index.isValid():
text = model.data(index).toString()
checked = selected = ""
checkState = model.data(index, Qt.CheckStateRole).toInt()
if checkState = Qt.Checked:
checked = " +checked"
if selectionModel.isSelected(index):
selected = " +selected"
test.log("|%s'%s'%s%s" %(" "*indent,text, checked, selected))
else:
indent = -4
#Only show visible child items
if(index.isValid() and treeView.isExpanded(index) or
not index.isValid()):
for row in range(model.rowCount(index))