質問

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!

役に立ちましたか?

解決

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)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top