talk.bindpose.com has been shut down on the 6th of March 2021. You can read a bit more about it here.

You are currently reading an archived copy of the latest content, with all the usernames deleted.

Parenting PySide2 Widget to main Maya window

by user101 posted 25-05-2018 | 2 comments

I designed a prototype UI from QtDesigner and converted the .ui file to .py

After some combining this and that from internet i managed to see my prototype but i couldn't parent it to the main Maya window just like regular cmds UI.

from maya import OpenMayaUI as omui 
from PySide2 import QtCore, QtGui, QtWidgets
from shiboken2 import wrapInstance

mayaMainWindowPtr = omui.MQtUtil.mainWindow() 
mayaMainWindow= wrapInstance(long(mayaMainWindowPtr), QtWidgets.QWidget)

class Ui_Form(QtWidgets.QWidget):
    def setupUi(self, Form, parent=mayaMainWindow):
        Form.setObjectName("Form")
        Form.resize(480, 640)
        self.verticalLayoutWidget = QtWidgets.QWidget(Form)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(170, 130, 261, 251))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setObjectName("verticalLayout")
        self.radioButton = QtWidgets.QRadioButton(self.verticalLayoutWidget)
        self.radioButton.setObjectName("radioButton")
        self.verticalLayout.addWidget(self.radioButton)
        self.radioButton_2 = QtWidgets.QRadioButton(self.verticalLayoutWidget)
        self.radioButton_2.setObjectName("radioButton_2")
        self.verticalLayout.addWidget(self.radioButton_2)
        self.toolButton = QtWidgets.QToolButton(self.verticalLayoutWidget)
        self.toolButton.setObjectName("toolButton")
        self.verticalLayout.addWidget(self.toolButton)
        self.checkBox = QtWidgets.QCheckBox(Form)
        self.checkBox.setGeometry(QtCore.QRect(150, 530, 70, 17))
        self.checkBox.setObjectName("checkBox")

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        Form.setWindowTitle(QtWidgets.QApplication.translate("Form", "Form", None, -1))
        self.radioButton.setText(QtWidgets.QApplication.translate("Form", "RadioButton", None, -1))
        self.radioButton_2.setText(QtWidgets.QApplication.translate("Form", "RadioButton", None, -1))
        self.toolButton.setText(QtWidgets.QApplication.translate("Form", "...", None, -1))
        self.checkBox.setText(QtWidgets.QApplication.translate("Form", "CheckBox", None, -1))



if __name__ == "__main__":
    Form = QtWidgets.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()

I also tried adding self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) to the setupUi method and loading the .ui file with pyside2uic.loadUiType but still no result.

 

by user23 posted 25-05-2018

I've used this in the past to figure this out. https://gist.github.com/liorbenhorin/217bfb7e54c6f75b9b1b2b3d73a1a43a

Would be interesting to hear if anyone knows of a more straightforward way of dealing with designer ui's.

 

by user101 posted 26-05-2018

I managed to hook the .ui file with the loadUiType function in the link. Everything works as i wanted to right now, thank you very much!