[Maya+PyQT]

Hi.

I’m new to this forum and I really appreciate such a high-level and helping community.

I’m a beginner at programming with maya or PyQt (still an animation student) although i know a few other languages.

I create a few classes as a skeleton for future tools, but i’m stuck in my UI class :

Here is the piece of code that cause trouble :


class Window (QtGui.QMainWindow) :
    ''' Creates, edits and stylizes a window '''
    
    def __init__(self, width, height, uiFile):
        
        
        # creates the Maya Window
        self.MWin = cmds.window(w=width, h=height)
        
        #getting the path to the UI File
        uiPath = os.path.join(cmds.internalVar(usd=True), 'esma', 'UIs', uiFile+'.ui')
        
        #loads the UIFile that has a widget as root
        widget = uic.loadUi(uiPath)
        
        #finds the Maya Window
        pyWin = mui.MQtUtil.findControl(self.MWin)
        
        #Maya window to Qt Window
        self.QWin = sip.wrapinstance(long(pyWin), QtGui.QMainWindow)

        #sets the widget as centralWidget for the window
        self.QWin.setCentralWidget(widget)


# creates a maya window (w:350, h:500) and passes "widget" as it's the widget.ui file that will be bind to it.
toolWindow = Window(350, 500, "widget")
cmds.showWindow(truc.MWin)

There.

The problem is that setting or even retrieving the centralWidget of a window makes maya FREEZE…

Just to clarify a bit : I want these windows to be dockable, that’s why I use the cmds.window and not a Nathan Hornes’ Window class type that I wasn’t able to dock in maya…

Maybe it’s a little fetched, and there is a way to handle windows created with PyQt in maya.cmds, but I don’t kno it. It’s the only solution I found after 16 hours researching the PyQT QMainWindow class, the MQtUtil class or the sip class… And it freezes ! :eek:

Thanks for your time and for the numerous great topics i find on this forum !

First answer explains why it’s causing it to crash.

Hi. Thanks for your answer that seems to explain the crash.

I’m searching again how to handle a QMainWindow with maya.cmds…

Does anyone know how to dock a QMainWindow in maya ??? Thanks !

Shame on me. I found the answer to my problem on this very website…

This topic shows how to dock a window created with PyQt.

In fact, the content of the dockControl has to be the Window class, that inherits the base and form classes of the loadUiType…

It’s suddenly all bright and clear ! Thanks dgovil for your answer anyway ! :D:

See you !

Congratulations on making another step on your journey into incredible frustration. I look forward to seeing many more ‘why the hell is Maya crashing’ threads in the future :slight_smile: