I don't think it should be much of a problem to create a QMainWindow that is a child of the Maya main window. It will know it isn't a top-level window. But for the menu stuff, it seems like it doesn't work too well to try and create the Application-level menus directly through Qt. You probably need to stick with going through the mel calls, to create the menus and items.
On Sat, Jul 12, 2014 at 2:14 AM, Marcus Ottosson <[email protected]> wrote: > I'm surprised you got anywhere with that script to be honest, but one > alternative might be to go with QWidget as opposed to QMainWindow as > QMainWindow probably tries making a separate window as opposed to an > additional widget amongst your menus. In fact, I think QMainWindow should > probably never be parented to anything as its more a top-level widget. > > But, if your goal is for artists to make their own menus, maybe there is a > better way to go about it. The way I've seen it done before is with a > separate window, a menu-editor if you will, that would generate the > equivalent script in Python or MEL. That way, you'd keep the resulting > menus independent of your tool, as well as possibly simplify your debugging. > > > On 11 July 2014 14:25, johan Borgström <[email protected]> wrote: > >> Hi Marcus and thanks! >> >> I have been using PySide for creating other tools, but for some reason I >> went back to old maya.cmds... >> I created a small test snippet, to experiment with the menu. >> >> The small menu test is working as expected, do you know how to add it to >> the maya main menubar? >> Using the snippet below if I add my "Root menu" to the maya mainWindow >> using the menuBar() to get a reference to the object I get a weird >> behaviour. Do you know a way to add it ? >> >> >> #import pprint >> #from maya import cmds >> from maya import OpenMayaUI as omui >> from PySide import QtCore, QtGui >> from shiboken import wrapInstance >> >> omui.MQtUtil.mainWindow() >> ptr = omui.MQtUtil.mainWindow() >> #widget = wrapInstance(long(ptr), QtGui.QWidget) >> widget = wrapInstance(long(ptr), QtGui.QMainWindow) >> >> >> test_win = QtGui.QMainWindow(parent=widget) >> root_menu = test_win.menuBar().addMenu('Root menu') >> sub_menu = root_menu.addMenu("Sub Menu"); >> l_1 = root_menu.addAction("Leaf 1"); >> l_2 = sub_menu.addAction("Leaf 2"); >> test_win.show() >> >> >> 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/7acbda71-d10a-4f74-94b9-290960155a2f%40googlegroups.com >> <https://groups.google.com/d/msgid/python_inside_maya/7acbda71-d10a-4f74-94b9-290960155a2f%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/CAFRtmOD1Qk35L9x%3DY%3DPvDLNAeTrYH%2Bu1b%2BQWSKufCcEmnTVGqQ%40mail.gmail.com > <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD1Qk35L9x%3DY%3DPvDLNAeTrYH%2Bu1b%2BQWSKufCcEmnTVGqQ%40mail.gmail.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/CAPGFgA2HLpvVkFjs-RCM9T5PQb0cS0cGW6kcJGnsqVW59xWCNQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
