[Python] How to delete an outliner panel child to a PySide2 window in Maya?

Discussão em 'Python' iniciado por Stack, Agosto 7, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to convert the Maya outliner to a QWidget. It works fine and shows up on screen as expected except the cleanup of it's outliner panel. I am tracking the panel of each instance through a unique object name and intend to delete them in the widget 's closeEvent. This is because I don't want the user's session to have multiple panels after the window/windows of anything using my custom widget is closed.

    Despite everything I tried, each new panel that is created is never deleted, Maya just increments the name. I am really not sure what's the solution here?

    Running this directly in script editor for my tests:

    import typing as _t

    from maya import cmds as _cmds
    from PySide2 import QtCore as _QtCore
    from PySide2 import QtWidgets as _QtWidgets


    class MayaOutliner(_QtWidgets.QWidget):
    def __init__(self, parent=None):
    super(MayaOutliner, self).__init__(parent)
    # Delete on close flag
    self.setAttribute(_QtCore.Qt.WA_DeleteOnClose, True)
    self._outliner_panel: _t.Optional[str] = None
    self._main_layout = _QtWidgets.QVBoxLayout(self)
    self._main_layout.setObjectName(f"MayaOutlinerMainLayout_{id(self)}")

    self._setup_ui()

    def _setup_ui(self):
    self.setWindowTitle("Maya Outliner")
    self.resize(300, 400)

    self._outliner_panel = _cmds.outlinerPanel(parent=self._main_layout.objectName())
    print(self._main_layout.objectName())
    print(self._outliner_panel)

    def closeEvent(self, event):
    if self._outliner_panel:
    _cmds.deleteUI(self._outliner_panel)

    # This should have been false?
    print(_cmds.outlinerPanel(self._outliner_panel, exists=True))

    super(MayaOutliner, self).closeEvent(event)


    window = MayaOutliner()
    window.show()

    Continue reading...

Compartilhe esta Página