Issue
I am creating a UI in Maya 2014 to manage custom attributes on transforms. So far, I have the transforms successfully generated, the UI will generate the items in the model (using QStandardItemModel), and finally displaying it with the QTreeView.
However, when I or the user changes the name of the item in the QTreeView, I would like to get the previous name and the proposed new name so I can update the custom attributes and the transform name.
I have searched all over Google, and I couldn't find anything that returns the previous and new name for the model/view, but I remember finding something using the QTreeWidget. The closest thing I could find was the QAbstractItemDelegate, but it doesn't look like it can provide the previous name value.
The only thing I can think of that I'm missing is something to do with the QModelIndex, but either way I'm stumped.
Thanks!
Solution
Re-implement the setData method of the model to get the old and new values during editing:
class TreeModel(QtGui.QStandardItemModel):
def setData(self, index, value, role):
if role == QtCore.Qt.EditRole:
print 'old:', self.itemFromIndex(index).text()
print 'new:', value
return QtGui.QStandardItemModel.setData(self, index, value, role)
Answered By - ekhumoro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.