Go to: Synopsis. Return value. Flags. MEL examples.

Synopsis

loadUI [-listTypes] [-uiFile string] [-uiString string] [-verbose] [-workingDirectory string]

loadUI is undoable, NOT queryable, and NOT editable.

loadUI lets you generate a Maya user interface from a Qt user interface (.ui) file. While creating the interface, if a Qt widget’s class is recognized, and a Maya-equivalent exists, the Maya-equivalent widget will be used. Any dynamic widget properties starting with a ‘-’ will be treated as a MEL key/value pair. Widget properties starting with a ‘+’ will be treated as a Python key/value pair. Properties will be applied to the widget upon creation. For additional details about ui files, please refer to Qt docs.

Return value

stringFull path name to the root control.

Flags

listTypes, uiFile, uiString, verbose, workingDirectory
Long name (short name) Argument types Properties
-listTypes(-lt) create
Returns the list of recognized UI types and their associated Maya command.
-uiFile(-f) string create
Full path to a user interface file to load.
-uiString(-s) string create
Load UI from a formated string.
-verbose(-v) create
Extra information about created controls will be printed.
-workingDirectory(-wd) string create
Sets the working directory, the loader looks for resources such as icons and resouce files in paths relative to this directory.

Flag can appear in Create mode of command Flag can appear in Edit mode of command
Flag can appear in Query mode of command Flag can be used more than once in a command.

MEL examples

// Note: mydialog.ui must already exist
string $dialog1 = `loadUI -f "/users/username/mydialog.ui"`;
showWindow $dialog1;

// Load from string
global string $dialog;
global int    $counter = 0;

// Define the button command callback
proc onClick() {
    global string $dialog;
    global int    $counter;

    $counter++;

    string $control = ($dialog + "|verticalLayout|mybutton");
    button -e
      -l ("Clicked " + $counter + " times")
      $control;

    print($counter +"\n");
}

// Create a dialog with a button from a UI description in string form
proc showDialog()
{
    // Since MEL doesn't support multi-line strings
    // we use a string array to hold each line ...
    string $ui[] = {
    "<?xml version='1.0' encoding='UTF-8'?>",
    "<ui version='4.0'>",
    " <class>Dialog</class>",
    " <widget class='QDialog' name='Dialog'>",
    "  <layout class='QVBoxLayout' name='verticalLayout'>",
    "   <item>",
    "    <widget class='QPushButton' name='mybutton'>",
    "     <property name='text'>",
    "      <string>Clicked 0 times</string>",
    "     </property>",
    "     <property name='-command'>",
    "      <string>\"onClick()\"</string>",
    "     </property>",
    "    </widget>",
    "   </item>",
    "  </layout>",
    " </widget>",
    "</ui>"
    };

    // .. and then concatenate entries together.
    string $dialogString = stringArrayToString($ui, "\n");

    // Next we load the UI from string with verbose output
    global string $dialog;
    $dialog = `loadUI -v -s $dialogString`;
    window -e -wh 200 50 $dialog;

    // Display the dialog
    showWindow $dialog;
}

showDialog();