Hey Johan,

The snippet I posted above on modifier keys, didn't that work for you?


On 12 July 2014 11:10, johan Borgström <[email protected]> wrote:

> Hi Justin and thanks for your reply,
>
> If I create menu items with cmds.menuItem(...) do you know if I can add a
> right click popup menu to a menuItem? Or can I check if a modifier was
> pressed while the user clicks the menu item? I want to create a menu where
> menu items can be deleted by RMB clicking the item and choosing "delete"
> from a popup menu. Another way would be to delete the item if a modifier
> key was pressed during the LMB click.
>
> The original question was not regarding Qt menus but Since Qt is used in
> other softwares in would be interesting to do it with Qt, and possible
> reuse the workflow.
> I had a look into the Maya Main window widget and found a QtGui.QMenuBar
> which seems to be the menubar that the main menu uses. I added my custom
> menu to this and it seems to work. This feels really hacky and not that
> solid to say the least :) but it is fun to experiment.
>
> I am on a mac and I am not sure how the menubar looks on a pc, but it
> seems like there are two "parallell" menus on mac. If I show the menubar
> that is found in the Maya main window it appears below the "original main
> menu". See the image attached. Below is the code that I use to add the menu.
>
> from maya import OpenMayaUI as omui
> from PySide import QtCore, QtGui
> from shiboken import wrapInstance
>
> # maya main window
> ptr = omui.MQtUtil.mainWindow()
> widget = wrapInstance(long(ptr), QtGui.QWidget)
> #widget.windowTitle()
>
> # get a reference to the menu bar
> menubar = [w for w in widget.children() if isinstance(w, QtGui.QMenuBar) ]
> menubar[0].show()
>
> # add menu and menuitems
> my_menu = menubar[0].addMenu("My Menu")
> sub_menu = my_menu.addMenu("Sub Menu")
> l_1 = my_menu.addAction("Leaf 1")
> l_2 = sub_menu.addAction("Leaf 2");
>
> I would be grateful if you have som ideas on how to add RMB popup menus to
> menu items or checking if a modifier was pressed. But is would also be
> interesting to se if we can get the Qt approach to work :)
>
> Best Regards,
> Johan
>
>
> On Friday, July 11, 2014 1:59:42 PM UTC+2, johan Borgström wrote:
>
>> Hi!
>>
>> I am building a basic menu populated with some menuItems. I want the user
>> to be able to add and remove menuItems to the menu. I have wrapped the menu
>> in a class and written some methods to help to add and remove menuItems. I
>> do not want to write a special ui to handle the removing of items, so my
>> idea is to check if the user holds a modifier key while clicking the
>> menuItem and if so delete it. Another idea is to use a right click popup
>> menu on the menuItem and have the option "delete item".
>> To add the command to the menuItem I use functools.partial. So to wrap it
>> up my questions are:
>>
>>
>>    - How can I add a right click popup menu to a menuItem.
>>    - How can I check if a modifier key was pressed when the menuItem was
>>    clicked.
>>
>> Best Regards,
>> Johan
>>
>>
>>  --
> 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/4ca132ba-898e-4c47-90c6-66a7785003d5%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/4ca132ba-898e-4c47-90c6-66a7785003d5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Marcus Ottosson*
[email protected]

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

Reply via email to