Reputation: 418
I have a very basic understanding of PySide. I'm hoping to parent a button to the existing Channel Box. However I'm not sure where to start outside of getting the main Maya window. (But I'm not even sure this is correct):
from PySide import QtGui, QtCore
from shiboken import wrapInstance
from maya.OpenMayaUI import MQtUtil
channelBox = wrapInstance(long(MQtUtil.findControl('mainChannelBox')), QtGui.QWidget)
Upvotes: 0
Views: 1493
Reputation: 1318
Messing up with Maya's UI can be a difficult task, there are two ways to do so.
First is to use maya.cmds
to add widgets to Maya's UI. The second one is to wrap, just like you did, a Maya widget in a Qt class.
The is a similar question here: How do I parent new, user-created buttons inside the Graph Editor window?
I answered with maya.cmds
code only and there is an other answer that might interest you as well using PySide.
Here is a solution:
nbIteration = 0
def getChildren(uiItem, nbIteration):
for childItem in cmds.layout(uiItem, query=True, childArray=True):
try:
print "|___"*nbIteration + childItem
getChildren(uiItem + "|" + childItem, nbIteration+1)
except:
pass
getChildren("MayaWindow|MainChannelsLayersLayout", nbIteration)
If you run this code, this will give you the name on the widgets contained in the Channel Box / Layer Editor
ChannelButtonForm <-- This is the form containing the 3 buttons on the top-right
|___cbManipsButton
|___cbSpeedButton
|___cbHyperbolicButton
ChannelsLayersPaneLayout <-- This is the layout containing the channel box and the layer editor. A paneLayout has a splitter to resize his childrens.
|___ChannelBoxForm
|___|___menuBarLayout1
|___|___|___frameLayout1
|___|___|___|___mainChannelBox
|___LayerEditorForm
|___|___DisplayLayerUITabLayout
|___|___|___DisplayLayerTab
|___|___|___|___formLayout3
Depending on where you want your button to be snapped, you'll have to choose a layout as parent for your button.
In this case, I'm placing a button on the top-left part of the Channel Box/Layer Editor, on the same level as the 3 checkboxButtons.
import maya.cmds as cmds
cmds.button("DrHaze_NewButton", l="HELLO", p="MayaWindow|MainChannelsLayersLayout|ChannelButtonForm")
As you didn't tell us where you want your button to be placed, you'll have to edit your question if you want something more appropriate.
Upvotes: 2