I have a QTreeView GUI based on editabletreemode.py in the PyQt examples. Inside the model, I re-implemented setData() for my need: for some out-of-bound value, I'm returning False, otherwise, it returns True
def setData(self, index, value, role=QtCore.Qt.EditRole):
if role != QtCore.Qt.EditRole:
return False
item = self.getItem(index)
result = item.setData(index.column(), value)
if result:
self.dataChanged.emit(index, index)
self.modified = True
print "setData() returning ", result
return result
Problem is, even when setData is returning False, GUI still accepts the changed value. So I now have inconsistent data between the model and view. What would make sense to me is that when setData() return False to reject the value, view should revert back to old value. Is this possible?
[SOLVED] Actually the return value of setData() doesn't seem to matter. The QTreeView seem to call data() to re-retrieve the value afterwards anyway. The problem I was having was because setData() changed the internal data even though it returned False.
If somebody could explain to me what is the return value of setData() is used for, that'd be great.
val? Shouldn't it bevalue? - yak