Maya Outliner in Pyqt doesn't charge

淺唱寂寞╮ 提交于 2019-12-11 11:25:25

问题


Well I'm trying to use a outliner in maya with Pyqt4 and python, My outliner is in a Qsplitter with other two panels, it seems the code is ok, but when I run the code sometimes the Outliner appears, sometimes doesn't appear

this is the code where I create the Outliner:

self.outliner = QWidget()
self.outliner.setObjectName("outliner")
self.outLayout = QGridLayout()
self.outLayout.setContentsMargins(0, 0, 0, 0)
self.outLayout.setObjectName("outLayout")
self.outliner.setLayout(self.outLayout)

outL = cmds.outlinerPanel(mbv=False, p="outLayout")

cmds.control(out, edit=True, visible=True, parent="outLayout")

And this is how I display it:

self.splitter1 = QSplitter()

self.splitter1.addWidget(self.list)

self.splitter1.addWidget(self.outliner)

What I need to modify to make it work every time

EDIT:

I Upgraded my code, deleting inecesaring lines, but still doesn't work the way i need


回答1:


Switching to answer format:

The current code would be better if you were not dependent on the hard coded names:

self.outliner.setLayout(self.outLayout)
#snip#
# in ordinary maya / python usage you'd do this....
panelLayout = cmds.formLayout("panelLayout", parent=self.outLayout)
# but in your original sample self.Outlayout is not a maya widget but a QT one
# so it doesn't resolve down to a string...
# the line below is the usual idiom
outliner = cmds.outlinerPanel("out", mbv=False, p=panelLayout)

that way the real names of the controls will be used and you're less vulnerable to strays with the same name. It's still good practice to delete strays - but it's hard to be sure without making the code very cumbersome.

Also, the line:

cmds.control(out, edit=True, visible=True, parent="panelLayout")

looks redundant - is it intentional? Is it a lefttover of an attempt to parent the outline? because the p= keyword ought to be doing your parenting for you.

Lurker update

As OP pointed out, code above wont' work - i've updated the sample to indicate the problem for the benefit of future readers.




回答2:


well this is what i finished doing:

The first part is the same

    self.outliner = QWidget()
    self.outliner.setObjectName("outliner")
    self.outLayout = QGridLayout()
    self.outLayout.setContentsMargins(0, 0, 0, 0)
    self.outLayout.setObjectName("outLayout")
    self.outliner.setLayout(self.outLayout)

then I "translate" Pyqt to maya to be able to assign the layout with any extra code

    panel = mui.MQtUtil.fullName(long(sip.unwrapinstance(self.outLayout)))
    cmds.setParent(panel)
    if cmds.modelPanel("outL", exists=True):
        cmds.deleteUI("outL")
    outL = cmds.outlinerPanel(mbv=False)
    cmds.control(outL, edit=True, visible=True, p=panel)
    ptr = mui.MQtUtil.findControl(outL)

Transform a Maya widget to a QWidget

    self.outPanel = sip.wrapinstance(long(ptr), QObject)

And Finally add the Widget to my Layout

    self.outLayout.addWidget(self.outPanel)


来源:https://stackoverflow.com/questions/16778552/maya-outliner-in-pyqt-doesnt-charge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!