Hi,
I’m facing a weird problem, I’m writing a UI in PySide2 and Maya 2018.
When the window is dockable it seems that I can’t access anymore to the QActions inside a QMenuBar.
Check the code below, is just a simplified test, but if you run it you will see that accessing to the QAction when is a dockable control gives the c++ already deleted error…
Any idea on how to solve it properly?
Thank you
from PySide2 import QtWidgets, QtGui, QtCore
from maya import OpenMayaUI as omui
from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
from shiboken2 import wrapInstance
mayaMainWindowPtr = omui.MQtUtil.mainWindow()
mayaMainWindow = wrapInstance(long(mayaMainWindowPtr), QtWidgets.QWidget)
class TestActions(MayaQWidgetDockableMixin, QtWidgets.QWidget):
def __init__(self, parent=None):
super(TestActions, self).__init__(parent)
self.setMinimumSize(200, 200)
main_layout = QtWidgets.QVBoxLayout()
self.setLayout(main_layout)
self.menu_bar = QtWidgets.QMenuBar()
# This menu is also available with right clicking on the tree widget
self.new_section = self.menu_bar.addMenu('Menu')
self.test_action = self.new_section.addAction('Do it')
self.test_action.setCheckable(True)
self.test_check_box = QtWidgets.QCheckBox('cb')
main_layout.addWidget(self.menu_bar)
main_layout.addWidget(self.test_check_box)
def try_action(self):
self.test_action.setChecked(True)
def try_checkbox(self):
self.test_check_box.setChecked(True)
# So far all good
test_win = TestActions(mayaMainWindow)
test_win.show(dockable=True)
# I call my method for editing the check box
test_win.try_checkbox()
# But when I call this, I get
# RuntimeError: Internal C++ object (PySide2.QtWidgets.QAction) already deleted.
# But only if the window is dockable
test_win.try_action()