That is exactly what I need. Learned something new today. Great!
One more thing though, I want to edit the text of the item. The text 
reverts back to original after edit. I am trying adding setData on the 
Custom item type with no success. Did search a hell lot on the Internet for 
an answer before posting here.

class CustomItem(QtGui.QListWidgetItem):

    USER_TYPE = QtGui.QListWidgetItem.UserType + 1

    def __init__(self, customitem, parent=None):
        super(CustomItem, self).__init__(parent, self.USER_TYPE)
        self.customItem = customitem

    def data(self, role):
        if role == QtCore.Qt.DisplayRole:
            return self.customItem.name()
        elif role == QtCore.Qt.EditRole:
            return self.customItem.name()
        return super(CustomItem, self).data(role)

    def setData(self, role, value):
        if role == QtCore.Qt.EditRole:
            self.setText(value)
            print value
            #self.setData(QtCore.Qt.DisplayRole, value)

The print command goes through, so setData is working. Is it possible to 
edit the text even after we set the data to return the object name?
Another solution would be to revert to a regular text list for the 
right-side listWidget that only contains names and not objects(custom type 
subclasses).

On Tuesday, June 16, 2015 at 4:03:03 AM UTC+5:30, crazygamer wrote:
>
> Hi,
> Am writing a renaming tool for maya. Its almost done but Im stuck on a 
> issue.
>
> I'm following Rob's book "Practical Maya Programming with Python". So I'm 
> keeping the Qt(PySide) code seperate from my maya code.
>
> Here's a quick laydown:
>
> #The window contains two list widgets (old names, new names) and two 
> buttons (load objects, rename objects). Old names list is not editable.
> # The UI is made with Qt Designer and converted to python using pysideuic.
>
> # The way its supposed to work:
> 1. Click "Load Objects" button to load selected objects(names) on both 
> list widgets.
> 2. User edits the text on the "new names" list widget.
> 3. Click the "Rename Objects" button to rename objects on the "old names" 
> widget with the naming from the "new names" widget.
>
> It works the first time. After that, I get this error:
>
> RuntimeError: Internal C++ object (PySide.QtGui.QListWidgetItem) already 
> deleted.
>
>
> I create the QListWidgetItem in the loop as I want the "new names" list to 
> be editable. I can 
> understand qt/python clearing it as garbage collection. How can I create 
> the QListWidgetItem properly so it doesn't get cleared on refresh.
>
> Can someone help me understand and write this efficiently so I can keep 
> the list editable and 
> refresh/recreate the QListWidgetItem on each object load. What I've 
> written is quite crude.
>
> The ui file(converted to python) is attached with this post.
> Here's the extracted code: (It also contains a test function so you can 
> test-run it with mayapy on a console)
> http://pastebin.ubuntu.com/11722053/
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/2595d370-36a8-44aa-ac95-a770181dccd6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to