«

»

Nov 20

Mixing PyQt4 widgets and Maya UI objects

A question came up in the Maya-Python mailing list that I thought was a really good topic, and should be reposted.

Someone asked how you can create maya UI objects and embed them within your main PyQt application. Specifically he wanted to create a modelPanel and embed it so that he would have a camera view within his own PyQt window.

Here is my example of how to achieve this…

You need sip and the MQtUtil functions to convert between maya node paths and python Qbjects. Its the same idea as having to use those functions to get a reference to the maya MainWindow, in order to parent your dialog.

10 comments

Skip to comment form

  1. ica

    As you described, I could ship a camera on PyQT UI.
    But, I want to do something more.
    I tried add pushbutton on camera view(a.k.a modelPanel) with addWidget method. However, it didn’t work well.
    I dreamed the camera view that could be controlled freely and have attached HUD items.
    Is there any way to solve my problem?

  2. Justin Israel

    @ica – If you are trying to overlay widgets on top of the camera view to simulate a HUD, then you would probably not want to add the PushButton to the Vertical Layout. That would just end up putting it underneath as it is laying widgets out in a column. What you probably just want to do is create the button and parent it to the Model Panel, but don’t add it to a layout. Then you can Move it to the location you want and it will sit freely on top of your camera view. I haven’t tested this but its my best guess :-)

  3. ica

    Sorry for late feedback.
    As you recommened, I tried “JUST” parent the QPushButton to Model Panel. Actually, I parented one of Model Panel’s children. It doesn’t mess up the camera view, and it can move on the view as I command.
    But, when I add a QPushButton once again, something happens. At the time additional creation, position is reset! I means that everytime I add buttons on Model Panel, I have to re-position all of the buttons. How can I lock them all?

    1. Justin Israel

      Im not exactly sure what happening. Can you email me directly and we can look at some of your code samples? As a workaround for now, you COULD just create a convenience method for adding a new button that adds it and repositions all the existing buttons again. Probably could save button positions to a dictionary each time and then use that for realigning them. It could be Maya’s parent widgets not liking free floating children not in layouts..Who knows. Ideally they should stay put.

  4. Jeremy

    Sorry for the noob comments but I used your installer for PyQt and then copied and pasted the above code in the script editor, ran the code, got no errors butI didnt get a window to open either. Is there something I missed?

    Thanks for your patience.

  5. Jeremy

    got it…show()

  6. Vlad

    Very impressive example, Justin, thank you!

    Can you help me please with modelEditor instead of modelPanel?

    The problem is – I can not wrap properly modelEditor, I am getting white panel in my widget…

    Thank you in advance!

    Vlad

  7. Carlo

    Hi Justin,

    I am using your way of implementing a modelPanel in my PyQt interface, but I was wondering if you got any crashing issues. If from the preferences window>UI Elements>Panel Configurations>Save panel layouts with file is checked on, Maya crashes 80 to 90% of the times upon saving. Do you have this issue?
    (I also tried other ways to implement the modelPanel and they give me the same result)

    Thanks.

    Carlo

  8. Rahul

    Works great, didn’t crash for me. Thanks for the tutorial

  9. Mark

    Hey Justin,

    Great example! Just wanted to ask if it was possible to embed a window instead of a modelPanel, having trouble trying to get the renderView/Panel stuck in place instead of the viewport. My means to an end is to basically grab the rendered image panel and not the toolbar but at the moment want to know if it’s even possible to put the render window in or it’s some special case where it won’t work.

    Cheers,

    Mark

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>