Working with PySide in Maya
PySide6 provides Qt Python bindings. The version of PySide6 used with Maya can be found on the Open Source Components page.
Some things to keep in mind when working with PySide6 are:
A unique
objectName()is needed for your widget so that it can be used and looked up throughmaya.OpenMayaUI.MQtUtil.findControl().There are no native sizing preferences for PySide6 widgets. You can use the
windowPrefcommand directly to set the sizing preferences.When docking windows, the size of the widget is retained and you can dock multiple windows to the same area so that you can switch among them via a tab as with Maya.
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:
from PySide6.QtCore import Qt from PySide6.QtWidgets import QMainWindow, QLabel from maya import OpenMayaUI as omui from shiboken6 import wrapInstance mw_ptr = omui.MQtUtil.mainWindow() mayaMainWindow = wrapInstance(int(mw_ptr), QMainWindow) 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 PySide6 scripts are provided in the Maya devkit in pythonScripts under the devkit directory.
