text()/setText() are convenience calls to data()/setData() with the
DisplayRole. So when we reimplement data/setData to handle the DisplayRole,
we don't then want to call setText(). We want to completely handle storing
our value. So I think you are working against yourself a bit in that logic.

But because you said that you don't want to directly work on the items, and
instead just perform an action when the button is clicked, this makes it
even easier. You don't even need the data/setData approach. All you really
need to do is let the QListWidgetItem continue doing its own default
behavior, but carry the custom item. You can then loop over all items when
the button is clicked and do the operation:

http://pastebin.com/UVhNkaMC

That example lets you edit the items in the list. When you click the
button, it does the rename on the custom item.

On Thu, Jun 18, 2015 at 3:21 AM crazygamer <[email protected]> wrote:

> Of course I can rename the object directly by doing the rename directly in
> setData:
>     def setData(self, role, value):
>         if role == QtCore.Qt.EditRole:
>             self.customItem.rename(value)
> Making the Display role also showing correctly as it should.
> I'll have to remove the "Rename Objects" button as the rename is happening
> directly on edit.
>
> Now that I have a custom item type in my ui (pymel node), I can do
> commands on the node directly(as above). Which I want to avoid if possible.
> Till now I have kept the Qt code separate from Maya code. I have one file
> with the ui code and another file with maya code. They interact through the
> controller using signals. (These methods learnt from Practical Maya
> Programming in Python Book) I like the efficiency of keeping them separate
> .
> I have a test function in the ui code so I can run the ui on a console
> with mayapy and see how it works. Since I made a custom item now, i had to
> import pymel in the test function. This takes a few mini-seconds to load.
>     def objs_list():
>         from pymel.core import createNode
>         #objs = []
>         objs = [createNode('polyCube'),
>                 createNode('polySphere'),
>                 createNode('polyCone'),
>                 createNode('polyCylinder')]
>         return objs
>
>     def load_objs():
>         controller.objList.emit(objs_list())
>
> I have the tool working acceptable now. These questions are just to know
> what is the preferred, efficient or "pythonic" way to write.
> Hope you can give me some inputs on how am I doing.
> Thanks for taking the time to answer. :)
> -Harshad
>
> --
> 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/9bb5346f-9fb7-4f86-afb3-e9ee45d3ac2d%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/9bb5346f-9fb7-4f86-afb3-e9ee45d3ac2d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAPGFgA2Jy56fhLOEq5G_KCH_q74fR-KDQJkAPB5RbqE8HNhimw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to