I am trying to check a node in a QTreeView automatically (eg when user loads some data). Manual checkbox ticking functionality works fine. I search the tree for the relevant item as per http://rowinggolfer.blogspot.com.au/2010/05/qtreeview-and-qabractitemmodel-example.html ie:
In the model:
def searchModel(self, person):
def searchNode(node):
for child in node.childItems:
if person == child.person:
index = self.createIndex(child.row(), 0, child)
return index
if child.childCount() > 0:
result = searchNode(child)
if result:
return result
node_index = searchNode(self.parents[0])
return node_index
def find_GivenName(self, fname):
app = None
for person in self.people:
if person.fname == fname:
app = person
break
if app != None:
index = self.searchModel(app)
return (True, index)
return (False, None)
Then I pass the relevant node into the model to set its check state eg
model.setData(node_index, 2, QtCore.Qt.CheckStateRole)
In the model:
def setData(self, index, value, role):
if role == Qt.CheckStateRole:
row = index.row()
self.args[row].checked = value
return True
But the checkbox for the relevant node does not get checked. Any ideas?