QT and Maya. How to use a QT Designer UI with Maya. No PyQt

I had several people ask me this and usually I say. Install PyQt … on every machine that needs it and voilla. However this can not always be done and if you want to share your tools online then you just want your tools to work out of the box.

*Now a days I’d say just use pyside. No need for custom PyQt instalations anymore.

So hereby a short tutorial on how to build a QT interface with Designer that work in Maya. Since maya 2012 QT Designer is shipped with the installation of maya. You can find it here “C:\Program Files\Autodesk\<maya version>\bin\designer.exe”. This opens QT designer default interface and you can start creating your own UI’s with simple drag and drop actions. I will not go in depth on how to actually use QT designer in itself as I’ll leave that for a later time.

There are a few standard QT widgets(buttons, sliders etc) that Maya recognizes. As soon as you load the UI in maya, maya will detect these and will replace the widgets with maya’s own version. This means that you can edit, query and delete most of these detectable widgets just by using maya mel or python or pymel. No need for pyqt (even though that does make it a 100 times easier).

Someone on the creative crash website wrote a great introduction to using the QT interface. http://www.creativecrash.com/tutorials/using-qt-designer-for-mel-interfaces Especially the list of controls is very useful to keep handy when you are getting started with QT. Now I will try to skip most of the things that are covered there but some stuff might overlap.

1) Giving commands to button:

In QT Designer you can add a Dynamic Property that gets called every time the button is clicked. You can do this by going into the properties , click the plus icon and click “other… ”
Then in the “Create Dynamic Property” window, write  “-c” without the quotes in the property name section. “-c” resembles the maya mel command for a button. You can add almost all commands like this. But most of the time you will only need “-c” or “-cc” for sliders etc. (*Note if you want to use python commands use a + instead of – )

Now in your property list you will see a new dynamic property at the end of the list. Here you can type any Maya Mel !!! command. However make sure its encapsulated in a string like this.

As you can see the command in itself needs to be in a string. This might cause some confusion as you will have to “escape” any other quotation marks by using a \. Do a search on escaping strings and you will find loads of information on this. As for python code just encapsulate it in a

command.

or use a +c instead of -c.
If you have multiple lines of python code you want to put in one line use the always dreaded and nightmarish ; (semi colon).
They still give me nightmares from the time I was using mel. haha

for example:

 

2) Loading the UI in maya.

This is as straightforward as it can get.  Make ourselves a simple window. Also added a dock control to it so its dock able everywhere.

Or load it with mel : (most simplistic version)

 

3) Getting values from widgets that are not supported by maya.

Now lets do something that we are not supposed to. Now this is where it starts to get interesting for me. Every time I tried to use QT I always ran into this problem. HOW THE HECK DO YOU GET A VALUE FROM A SPINBOX or a DIAL or any other cool custom downloaded widget etc. It always bugged the hell out of me for not being able to find a stable way. But now I seem to have found a solution and the answer is “signals and hidden line edits”.

You can connect any widget to a line edit. To do this create a “line edit” anywhere in the UI. Preferably where it does not edit your layout but you can easily access it.
Go into “Edit Signal / Slots” Mode (F4) and click and drag from your widget to the “line edit”. This opens up a new window that allows you to link a value to the text field (providing the widget support exporting a Qstring)

Now on change of the original widget (a double spin box in this case) the “line edit ” in itself will be updated with the value. However if the user does not change the value the line edit will be empty. Which is why its a good idea to give it the same default value as the widget.

 

4) interacting with the UI from within maya WITHOUT USING PYQT.

So now when we load our QT Ui inside of maya we can query the text of our line edit every time we want to by using the following line of code:

 

6 thoughts on “QT and Maya. How to use a QT Designer UI with Maya. No PyQt

  1. Thank you for posting this stuff! It helped out a lot… However, I noticed a few issues…

    -c Works perfectly.
    +c Does not.
    “python(\” your python code goes here\”)” Did not seem to help at all and, instead, produced a syntax error.

    I’m utilizing Maya 2014 and the QT Designer package that came along with it… I’m noticing it doesn’t work very well with Python, can you, perhaps, provide more detail on how to get this working?

    Many thanks!

    -Criso

    • Hi Criso,

      Yeah you are right I made a mistake in the explanation. Its a bit of a nightmare to get it working correctly.

      But the code “python(\”print ‘test’\”)” does work … however you have to include all quotes.
      I hope this screenshot will help:

      So if you want to use a -c mel command
      python qt

      And this is the command for python +c:
      pythonbtn

      Hope that helps.
      Cheers,
      Jan

  2. Hi. I have a button setup in Designer UI, which has the “-c” flag, with the command calling a procedure of my own, which I wrote in Mel. Everything works here, problem is, I have to make the procedure global, otherwise I get the error that it cannot be found. Is there a way around this?

    • Hi,
      Hmm good question, first off, don’t use mel anymore XD. Buuut thats not helpful of course.

      But fun challenge to figure out.
      The easiest way I can think of is chaining the mel command with a source statement.

      chainingMelStatements

      Note that you do have to double escape the source statement.
      "source \\"myMelScript.mel\\";myFunction();print \\"testing\\";"

      Hope that helps. Let me know if it doesn’t.

Leave a Reply to Jan Cancel reply

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