PySide2 provides Qt Python bindings. The version of PySide2 used with Maya can be found on the Open Source Components page.
Some things to keep in mind when working with PySide2 are:
objectName()
is needed for your widget so that it can be used and looked up through maya.OpenMayaUI.MQtUtil.findControl()
.windowPref
command directly to set the sizing preferences.You must parent your widget under an existing Maya widget to prevent it from being destroyed by the Python garbage collector. You can parent the widget to the Maya main window or the dock control. For example:
hello = QLabel("Hello, World", parent=mayaMainWindow)
hello.setObjectName('MyLabel')
hello.setWindowFlags(Qt.Window) # Make this widget a parented standalone window
hello.show()
hello = None # widget is parented, so it will not be destroyed.
Several example PySide2 scripts are provided in the Maya devkit in pythonScripts
under the devkit
directory.