Using QT Designer for MEL Interfaces_huadingjin_新浪博客

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.

As I mentioned in previous page we need to connect some of the controls to others for having access by MEL. For this, you need to connect them by hand. QT is not like MEL. in MEL you can assign a string text from one control to an integer variable as long as that text contains just numbers but, in QT it's not possible.
Now hit "F4" to go to "edit signals/Slots" mode (or you can choose it under edit menu). In this mode you can't move controllers around but you can connect them with each other with similar attributes. Now select the spin box and drag it to line edit. As you can see a red line will appear with an arrow at the end. In picture below I dragged dial control to spin box (if you want to use dial control you can't connect it to double spin box because double spin box will receive just double values and dial will send integers so you need to connect it to spin box.)
006
Now a new window will pop up. Pay attension that i checked "show signals and slots inherited from QWidget". Keep this setting on because some of the attributes will be hidden by normal settings (like setVisible).
007
The left hand list is your driver list and the right hand one is your driven. Now select valueChanged(int) from left list and setValue(int) from right side and hit OK. Now drag spin box over line edit and select valueChanged(QString) from left and setText(Qstring) from right. As you see spin box can output bot QString and int values (the attribute below in list) so if you want to connect a spin box to a slider you should choose the one that has int in it's name. Now hit OK. Now hit "F3" to go back to design mode.
The next thing we need to do is to give our push button and horizontal slider action in Maya. Select push button and in property editor (right side bar of QT designer) hit the plus button and select string from menu. In the opened window type -c (as you remember it's a flag for button command of maya, you can add as many flags as you need like this.)
008
009
Now you have a dynamic attribute and you can type anything in it. Now qnother line edit at left side of the slider. in property editor change the objectName to slider_view. Change it's enabled attribute and uncheck it. Now select the horizontal slider and add a dynamic attribute. Type -dc (for dragCommand flag of inSlider). Now move down the list to see your attribute and type "textField -e -tx #1 slider_view" (with " marks!). the #1 in this command will return the value of the same controller (slider in this case).
Now save the project from file menu in your script folder of maya as test.ui . In next page we will import this UI in Maya. 

搜索

复制


OK, we made our UI and now we need to import it in Maya. Open the script editor and right the code below :

OK, we made our UI and now we need to import it in Maya. Open the script editor and right the code below :

string $d=`internalVar -usd`;

string $dialog = `loadUI -uiFile ($d+"/test.ui")`;

showWindow $dialog;

 

Now select the code and hit CTRL+Enter to execute it. congratullation, your interface will be opened. But wait a minute, we still can see the spin box and that's not good. We don't need it. Now how can we hide it in QT? The answer is simple, select it in QT designer and in property editor change the hight and wide to 1 ! This way we hide it from others in view port. The picture below shows the same UI in Maya with a little change in place for some elements. As you can see, changing the dial and horizontal slider changes the text of the line edit control. Now you can use textField command and refer to these controls to query the text and put it in integer values. What if you need float values when sliding the slider? The answer is simple, you can change the command in -dc. Change the min and max value to 0 and 100 and add /100 after #1. Now openning UI in Maya and dragging horizontal slider, you can see that the text box will show you float number between 0 and 1 ! (I didn't do this step in picture below but I hide the spin box, the one you see is the double spin box that do nothing until you connect it to something.)

016

Now what if I want to make my UI dockable? Add the code below after your current code in script editor.

 

string $layout1=`paneLayout -cn "single" -p $gMainWindow`;

dockControl -aa "all" -a "right" -fl off -con $layout1 -l "MainWindow";

control -e -p $layout1 $dialog;

 

Now select your code and hit CNTL+Enter to execute it. Congratullation. Now you have a dockable UI that works in Maya. Now you can go and add your own controls and make your progress in Maya. If you had any question ask me by email to ali cgfx3d com.

 

Have fun.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值