QT Interfaces in Maya

Written by mattanimation. Posted in Maya, pyQT, Python, UI

There are a many sites that have information about how to setup/create a user interface in Maya using the QT frameworks components, specifically using Qt designer. Here are a couple of links I found especially useful:

http://ivoxelstudios.com/blog/?p=51

Now this one is pretty cool because Chris covers something that I have found to be kind of annoying to with loading a UI which is wanting to be able to grab the controls from the UI.

http://www.chris-g.net/2011/06/24/maya-qt-interfaces-in-a-class/

Another great resource is from John Neumann that covers creating a UI and loading it in Maya and then adding functionality using MEL.

http://www.animateshmanimate.com/2010/07/19/maya-andqt-tutorial/

Here is a video tutorial straight from Autodesk.

http://area.autodesk.com/blogs/stevenr/maya_2011_highlight_qt_user_interface

I just wanted to add to the resource results in google and put the most basic information needed to get started which is, what do I need to do to see my interface after I have created it?

well here is the most basic code I could strip it down to(python version of course):

import maya.cmds as cmds

pathToFile = 'path/to/your/file.ui'
qtWin = cmds.loadUI(uiFile=pathToFile)
cmds.showWindow(qtWin)

Now, if that’s not easy and straight forward I don’t know what is.
But now how do you edit your components? Well, whatever you named the object in QTDesigner will be the name of the object in Maya, just refer to it in string form, for example, if I had a textScrollList in my UI I would type something like the following to add an item to it:

cmds.textScrollList('nameOfMyWidget', e=True, a='smellyFeet')

So as you can see it’s easy to type the names of widgets and edit them, but wouldn’t it be nice to have all of them stored in a dictionary somewhere for easy reference? The link to Chris G’s blog post talks about this is is a must read.

One last thing worth mentioning is the docking ability to the interface, since this IS one of those features that everyone wants at least try one time even if it’s not always necessary. This information is at the end of the autodesk video but it’s nice to just have the code you need on had right, plus google can’t really search the video for code right?

so add this to the code above and comment out the cmds.showWindow part

dockLayout = cmds.paneLayout(configuration='single', parent=qtWin)
cmds.dockControl(allowedArea='all', area='right', floating=True, content=dockLayout, label='Custom Dock')
cmds.control(qtWin, e=True, parent=dockLayout)

and thats it! You can play with some of the args to get the functionality right, like if you set “floating” to false it will start out as docked to the right side of your layout in Maya. Good Luck!

Tags: , , , , ,

Trackback from your site.