Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Mixing PyQt4 and Maya UI objects
from PyQt4 import QtCore, QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as mui
import sip
class MyDialog(QtGui.QDialog):
def __init__(self, parent, **kwargs):
super(MyDialog, self).__init__(parent, **kwargs)
self.resize(800, 600)
self.setWindowTitle("PyQt ModelPanel Test")
self.verticalLayout = QtGui.QVBoxLayout(self)
# need to set a name so it can be referenced by maya node path
# First use SIP to unwrap the layout into a pointer
# Then get the full path to the UI in maya as a string
layout = mui.MQtUtil.fullName(long(sip.unwrapinstance(self.verticalLayout)))
paneLayoutName = cmds.paneLayout()
# Find a pointer to the paneLayout that we just created
ptr = mui.MQtUtil.findControl(paneLayoutName)
# Wrap the pointer into a python QObject
self.paneLayout = sip.wrapinstance(long(ptr), QtCore.QObject)
self.cameraName =[0]
self.modelPanelName = cmds.modelPanel("customModelPanel", label="ModelPanel Test", cam=self.cameraName)
# Find a pointer to the modelPanel that we just created
ptr = mui.MQtUtil.findControl(self.modelPanelName)
# Wrap the pointer into a python QObject
self.modelPanel = sip.wrapinstance(long(ptr), QtCore.QObject)
# add our QObject reference to the paneLayout to our layout
def showEvent(self, event):
super(MyDialog, self).showEvent(event)
# maya can lag in how it repaints UI. Force it to repaint
# when we show the window.
def show():
# get a pointer to the maya main window
ptr = mui.MQtUtil.mainWindow()
# use sip to wrap the pointer into a QObject
win = sip.wrapinstance(long(ptr), QtCore.QObject)
d = MyDialog(win)
return d
dialog = show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.