Created
December 27, 2012 02:37
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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