It is important to note that saving user interfaces from QT Designer will result in a UI file that is not compatible with Python nor Maya, naturally. Instead, this must be converted into usable Python code. There is a tool named pyside-uic which is built for the purpose of converting the aforementioned format to Python. I have experimented in the past using scripts external to Maya to convert these files, but discovered that the workflow was not pleasing, and thereafter switched to implementing a conversion script, which will be shown below, within Maya itself.
import os from pysideuic import compileUi import maya.cmds as cmds def convert_qtui_to_py(): caption = 'Select QT UI file...' fileFilter = 'QT UI Files (*ui)(*.ui)' result = cmds.fileDialog2(ds=2, ff=fileFilter, cap=caption, fm=1) if None == result: return try: py_file = open(os.path.splitext(result) + '.py', 'w') compileUi(result, py_file, False, 4, False) py_file.close() cmds.warning('File converted.') except IOError: cmds.warning('Could not open file!')
Feel free to integrate the above code snippet using whichever method you please. Personally, I have it saved in a scripts folder, and then have a shelf icon which calls the appropriate method when pressed. As can be seen in the above code sample, we are importing compileUi from the pysideuic module. Importing this module gives us the ability to convert the GUI files. The rest of the code is standard Python for opening files, stripping extensions, and so on. In the case of this simple script, the output from the converted UI file is saved with the same name, but with a py extension. This, of course, can be modified to personal taste.
If you open a resulting converted Python file, it should be obvious that the code is not suitable for use straight away, especially in Maya. Instead, there's some work we need to do first.
The current implementation of the converter (disclaimer: Maya 2016 and below) outputs two methods: setupUi() and retranslateUi(). The former builds the interface itself and the latter sets the localized text of each component that requires it.
The following description is not intended as a tutorial, but instead, an overview, so please check out some of my previous plugins and scripts for practical, real-world examples. There are other methods for implementing the converted GUI code into your own plugins, but my personal approach is to inherit my plugin's class from QtGui.QMainWindow, which can be found by importing QtGui from the PySide module. While you are at it, import QtCore, also, as it is essential to component positioning and sizing. Note that due to inheriting from this, you should call super's init method as follows: super(YourClassName, self).__init__(). The code from the setupUi() and retranslateUi() methods I usually place within a single method and call it upon initialization of the class, appending both self.show() and self.raise_() at the end in order to display the interface. Please note that the name of your dialog from the designer will be extensively used in the output Python code, and must instead be replaced with self.