Connect rename command in QListWidget item edit

55 views
Skip to first unread message

Lien

unread,
Apr 20, 2023, 3:08:00 PM4/20/23
to Python Programming for Autodesk Maya
Hi

I am trying to make a QListWidget items window and want to connect the cmds.rename() to take whatever user edit the new item name with double click.

I am currently connect things up like:
geo_list_wdt = QtWidgets.QListWidget()
geo_list_wdt.itemDoubleClicked.connect(self.rename_item)

Is there a way I can query the name that user input/edit and connect up with the rename cmd  (cmds.rename(currentItem_name, user_input)) ?

Thank you,





Justin Israel

unread,
Apr 21, 2023, 6:30:59 PM4/21/23
to python_in...@googlegroups.com
Here is an example with a few of the many ways this could be solved:
https://gist.github.com/justinfx/134992bd323c76d55af2c1b2750ebd84

In the MyListWidget example, it is implementing the edit() hook to capture when an item edit operation is starting, so that we can remember the current value before it changes.
Then when the itemChanged signal fires, we can handle the slot and compare the previous value to the current one and choose to call rename()

The MyListWidget2 example is almost the same, but instead of implementing edit(), it uses the doubleClicked signal to track the current text value before it changes. I think I like the previous approach better because it gives you more specific control over when the edit operation is actually starting. You can even check the specific edit trigger type if you wanted.

Justin


--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/26a95e4c-ee05-4bac-afb1-98608492235cn%40googlegroups.com.

Lien Chen

unread,
Apr 22, 2023, 3:14:27 PM4/22/23
to python_in...@googlegroups.com
Hi Justin,

Thank you so much for showing/explaining ways to get the current and edited item, I tested it out in code and understand what you mean for their differences;

Thanks again for the help :) !

Lien

 

Reply all
Reply to author
Forward
0 new messages