Maya Outliner in Pyqt doesn't charge

2019-08-11 09:13发布

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

2条回答
Fickle 薄情
2楼-- · 2019-08-11 09:53

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)
查看更多
趁早两清
3楼-- · 2019-08-11 09:56

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.

查看更多
登录 后发表回答