Skip to content

Instantly share code, notes, and snippets.

Created December 27, 2012 02:37
Show Gist options
  • Select an option

  • Save anonymous/4384994 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/4384994 to your computer and use it in GitHub Desktop.
Example of using an existing PyQt4 class layout and adding Maya UI elements into the child layouts.
import maya.cmds as cmds
import maya.OpenMayaUI as mui
from PyQt4 import QtCore, QtGui
import sip
class Window(QtGui.QWidget):
"""
An arbitrary layout representing something
that could have been created using Qt Designer.
Has main layout, and then child widgets with their
own layouts.
Set object names, so that Maya will use them in the
path structure.
"""
def __init__(self, parent=None):
super(Window, self).__init__(parent)
self.setObjectName("MyWindow")
self.layout = QtGui.QVBoxLayout(self)
self.layout.setObjectName("mainLayout")
self.hgParent = QtGui.QWidget()
self.hgParent.setObjectName("hgParent")
self.hgParentLayout = QtGui.QVBoxLayout(self.hgParent)
self.hgParentLayout.setObjectName("hgParentLayout")
self.layout.addWidget(self.hgParent)
win = Window()
win.show()
win.raise_()
win.resize(600,400)
# Get a pointer to the QObject (the layout)
layout_pointer = long(sip.unwrapinstance(win.hgParentLayout))
# Get the Maya path to the layout:
# "MyWindow|mainLayout|hgParentLayout"
path = mui.MQtUtil.fullName(layout_pointer)
# Just set it as the current parent UI
cmds.setParent(path)
# Create a hyper graph panel, which will end up in the layout
panel = cmds.hyperPanel()
# Verify the location of the new hypergraph
print win.hgParentLayout.itemAt(0).widget().objectName()
# PyQt4.QtCore.QString(u'hyperPanel1') #
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment