Pyside : Attach cmds.popupmenu to QListWidget

27 views
Skip to first unread message

Fransuzich

unread,
Feb 5, 2019, 1:16:45 PM2/5/19
to Python Programming for Autodesk Maya
Hello everyone,

I can't figure out how to attach a maya popupMenu to a QlistWidget (or QlistView).

It works fine when i attach it to a QFrame for example, but nothing append when calling it on a QlistWidget.
My Pointer to the QlistWidget seems fine to me as it print |||testListWidget (and ||frame0 when attaching on a QFrame, and working inside hat Qframe).

self.listWdtPointer  = long(shiboken2.getCppPointer(self.listWdt)[0])

self.listWdtPointerFullPathName = omui.MQtUtil.fullName(self.listWdtPointer)

                print self.listWdtPointerFullPathName ---->  |||testListWidget

                cmds.popupMenu(mm=True,parent=self.listWdtPointerFullPathName)
cmds.menuItem(rp='N',l='Test')

Has anyone ever experienced that issue ?

Thanks

Justin Israel

unread,
Feb 5, 2019, 2:02:18 PM2/5/19
to python_in...@googlegroups.com
It could be a few different things. Those multiple ||| characters in the widget path indicate that you haven't used setObjectName() on the widgets or layouts above the list widget. In my experience that can cause problems when trying to mix Qt widgets with Maya UI commands. 

Or it could be whatever logic Maya is using to apply the popupMenu cmd to a widget and it possibly conflicting with a QListWidget already having context menu logic of its own. 


Thanks

--
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/e3f1092b-f301-4dd9-9972-b4e4965d6780%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Fransuzich

unread,
Feb 7, 2019, 9:35:19 AM2/7/19
to Python Programming for Autodesk Maya
Finally got a workaround from Combi, big thanks to him :)

The global idea is to redirect the QlistWidget rightClick mousePressEvent to a method where we ignore it:

self.listWdt.mousePressEvent = self.listWidgetMousePressEvent

def listWidgetMousePressEvent(self, event):

button = event.button()

if button == QtCore.Qt.MouseButton.RightButton:
event.ignore()     
else:
QtGui.QListWidget.mousePressEvent(self.listWdt, event)

Thanks anyway Justin for your feedback.

Fransuzich

unread,
Feb 7, 2019, 9:42:28 AM2/7/19
to Python Programming for Autodesk Maya
And finaaly let me add ( like Justin said ) that  all widgets names must be defined properly with setObjectName to avoid the menu not showing (but existing).


On Tuesday, February 5, 2019 at 7:16:45 PM UTC+1, Fransuzich wrote:
Reply all
Reply to author
Forward
0 new messages