Using QT Designer for MEL Interfaces

Report this File

Qt-logo

Views:

62,502

Updated:

May 04, 2010

Readership Level:

Basic

Tags:

Maya Versions:

2011

Platforms:

windows

Owner:

Language:

English

When for the first time I saw Maya 2011 and learned about QT I thought that it must be hard. Most of the time companies won't integrate other things in their programs sufficiantly. But, after a week of working with QT, I must say that god bless all those people in Autodesk.
Developing an interface in QT is simple and fast and it works like charm. You need to download QT and install it. After installation, you'll have a program called "Designer". Opening it will give you option to choose from diferent window templates.
001
Now we select "Main window" and hit "Create" button. A new blank window will appear. This window has a menu bar (on top) and status bar (on bottom). Most of the time you don't need these so you can right click and delete them but if you want to have menu bar then you can use it.
In the picture below I gathered almost all the awailable controls that will work with Maya (directly or indirectly).
005
1-push Button (under Buttons group) --------------------Maya command to access------------> button;
2-radio button (under Buttons group) --------------------Maya command to access------------> radioButton;
3-check box(under Buttons group) -----------------------Maya command to access------------> checkBox;
4-combo box (under containers group) ------------------Maya command to access------------> optionMenu;
5-line edit (under input widgets group) -------------------Maya command to access------------> textField;
6-spin box (under input widgets group) ------------------Maya command to access------------> NONE
7-double spine box (under input widgets group)---------Maya command to access------------> NONE
8-dial (under input widgets group) ------------------------Maya command to access------------> NONE
9-list view (under item views model based) --------------Maya command to access------------> textScrollList;
10-horizontal slider (under input widgets) ----------------Maya command to access------------> intSlider;
11-label (under display widgets group) -------------------Maya command to access------------> NONE
12-progress bar (under display widgets group) ----------Maya command to access------------> progressBar;
13-vertical slider (under input widgets) -------------------Maya command to access------------> intSlider;
14-horizontal line (under input widgets) ------------------Maya command to access------------> NONE
15-vertical line (under input widgets) ---------------------Maya command to access------------> NONE
16-group box (under containers group) ------------------Maya command to access------------> NONE
17-tab widget (under container group) -------------------Maya command to access------------> tabLayout
18-main window --------------------------------------------Maya command to access------------> window;

Now, as you can see, we have no command to access spin boxes or dial control so we need to redirect them to somthing else in the UI that is accessible with MEL.
Tutorial_next_page

Comments

Dashboard_avatar
May 18, 2010
Post id: 11215
Report this comment to moderators [SPAM]

Thanks a lot. This is awesome...Great write up.

Oh and to those who want it;

http://qt.nokia.com/qt-in-use/autodesk

View John Neumann's profile
Jul 12, 2010
Post id: 11777
Report this comment to moderators [SPAM]

I'd like to point out that this is wrong:

9-list view (under item views model based) --------------Maya command to access------------> textScrollList;

That view will NOT give you any feedback at all. However, if you use the List Widget (under Item Widgets Item-Based), you will be able to use that to populate a textScrollList. Hope this helps someone else.

View css_maya 's profile
Aug 14, 2010
Post id: 12146
Report this comment to moderators [SPAM]

UPS
thanks man

Dashboard_avatar
Aug 25, 2010
Post id: 12251
Report this comment to moderators [SPAM]

Could i use this tutorial for modifying the main Maya GUI?
I would add a bottom for Outliner, graph editor and Hypergraph, beside the three trasform fields in the status line. Thanks

Dashboard_avatar
Aug 28, 2010
Post id: 12306
Report this comment to moderators [SPAM]

>> Yanez

No, but adding a button to the outliner, grapheditor and hyopergraph is pretty trivial in even older mayas. All you need is to know the name of the gui item you want to inject stuff into and inject. Hees a fairly simplistic example, note im doing a bit of sloppy job attaching it because im not so much on time and i attach it to the right just before the show hide attribute editors because its easier (otherwise id have to change the command toggleInputField):

$formName=("MayaWindow|mayaMainWindowForm|"+
"formLayout1|formLayout12|formLayout13|"+
"formLayout41|formLayout42");
setParent $formName;
$button=`button -l demo -c OutlinerWindow`;

formLayout -edit
-attachForm $button "right" 5
$formName;

You can make this considerably neater BUT, i suggest you do not make theese buttons make hotkeys instead, its better faster and doesnt slow down you usage experience as a small button would (yes they would because the statusline is so small in area)

Dashboard_avatar
Jan 05, 2011
Post id: 13453
Report this comment to moderators [SPAM]

How to parent two windows on one layout

View css_maya 's profile
Jan 05, 2011
Post id: 13456
Report this comment to moderators [SPAM]

dare daree, do you mean when you are designing in QT? or do you mean adding two different QT UI's to two different maya panels?

Dashboard_avatar
Jan 16, 2011
Post id: 13548
Report this comment to moderators [SPAM]

Many thanks for the tutorial, it's a great help. I'm stuck on one thing though, I can't seem to get the float part working.

I'm using this -
"textField -e -tx (#1/100) sliderView"

but the textField only displays zero for the range of the slider and switches to 1 at the end.
How do I make it see the float values?

Dashboard_avatar
Jan 16, 2011
Post id: 13550
Report this comment to moderators [SPAM]

I found a way that works, instead of doing the calculation in the -dc command on the slider I just added a global procedure called 'update' which takes the value from the slider and divides by 100, then feeds this into the text field.

I'll post the MEL below in case it's handy for someone else.

[CODE]
//set the scripts directory so we can load our ui file
string $scriptsDirectory = `internalVar -usd`;
//load the ui file
string $testWindow = `loadUI -uiFile ($scriptsDirectory+"/test.ui")`;
//show the window
showWindow $testWindow;

// set up the initial value for the text field
update;


// procedure to update the text field as the slider changes - this is driven from the slider dragCommand
global proc update(){
float $sliderVal = `intSlider -q -value horizontalSlider`;
float $readOut = ($sliderVal/100);

textField -e -text ($readOut) sliderView;
}
[/CODE]

Dashboard_avatar
Feb 22, 2011
Post id: 13883
Report this comment to moderators [SPAM]

good

Dashboard_avatar
Mar 10, 2011
Post id: 14016
Report this comment to moderators [SPAM]

Great tut....

How to implement this in maya 2009 or below.....?

and is there a script/ document to know the maya gui item, so that i can add some items as per the requirements.....

View John Neumann's profile
Mar 13, 2011
Post id: 14046
Report this comment to moderators [SPAM]

@pblnrao3d - Unless you're using PyQt as a wrapper and writing it in Python you can't.

Dashboard_avatar
Mar 14, 2011
Post id: 14057
Report this comment to moderators [SPAM]

Thx john for ur response....

As per my understandings, correct me if i am wrong. I think PyQt is s CUI based. So there is no other way to create a GUI in any other tool/application (i mean creating GUI by Drag & Drop like Qt Designer). Only way is to we need to code it.

And you did not say abt way.... how to find the maya global variables like......

Maya Object/Item - In MEL - In Python
-------------------------- ------------ ---------------
Maya Main MenuBar - $MainWindow - MayaWindow

Dashboard_avatar
Jun 04, 2011
Post id: 14638
Report this comment to moderators [SPAM]

Hi,

I am stuck. Ok This is what I am trying to do. Very simple. I have a slider and a button made in QT designer. What I want is when I press the button, I want to create a sphere in Maya using MEL for the radius equal to the slider value. So I went ahead and added a dynamic property to the button
-command "sphere -ch on -o on -po 0 -ax 0 1 0 -r #1 radiusHSlider -s 22 -nsp 22"

The window loads properly in Maya (using "loadUI -uiFile"). When I select the button, I get an error "// Error: No object matches name: radiusHSlider //

"radiusHSlider" is the object name of the slider in QT designer. Why maya cannot find its name.

Please advise.

Thanks
ravi

Dashboard_avatar
Jun 06, 2011
Post id: 14654
Report this comment to moderators [SPAM]

Thanks for this tutorial , it has been extremely helpful and made my task very easy! cheers!

Dashboard_avatar
Jun 07, 2011
Post id: 14659
Report this comment to moderators [SPAM]

Checkout the tutorial "Introduction to Maya UI in QT and Python" at http://ivoxelstudios.com/blog/?p=51

Dashboard_avatar
k j
Aug 28, 2011
Post id: 15198
Report this comment to moderators [SPAM]

Hi,
I have a problem with tabLayout/ tab widget. I created tab widget in QT Creator and name it for example “tabContainer”. After that, I tried to have a access to it form mel, and I couldn’t. The command “tabLayout -ex tabContainer;” gave mi 0. It works for button and some other stuffs. Does the tabLayout / tab widget will return any feedbuck?

Dashboard_avatar
Aug 06, 2012
Post id: 16690
Report this comment to moderators [SPAM]

Hi, tried to use the label widget to add a image into my gui, but when i load the ui file in maya it doesnt show. is there any solution for this?

Write a Comment

You must be logged in and have verified your email address to leave a comment. Login or create an account