1

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

  • You're using absolute names in your reference between panels. Are you sure you're not failing because there is an undeleted 'panelLayout' or 'outLayout' lying around that might be causing problems? – theodox May 28 '13 at 02:46
  • @theodox Maybe, i have to check, but if that were the case, `deleteUI` should delete it, doesn't it? – Alfredo Díaz May 29 '13 at 15:22

2 Answers2

0

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.

theodox
  • 12,028
  • 3
  • 23
  • 36
  • I'm not sure what you really mean with the hard coded names, but well i think you refer something like `panel = cmds.formLayout(parent="outLayout")` because i try with the `parent=self.outLayout` and it send me an error, but even with the change it still have the same issue. And the 'control' i used because is the way i found on internet to call an ouliner, but if i take it out, it seems work fine – Alfredo Díaz May 29 '13 at 22:32
  • Ah - I see: outLayout is the QGridLayout, not a typical maya.cmds object: those always return the string name of the actual control (which might not be the name you asked for... the whole reason for doing it this way) My bad. However you might find this link useful: http://tech-artists.org/forum/showthread.php?2845-PyQt-Widget-in-Maya-Mel-UI-problem – theodox May 30 '13 at 03:17
  • It help me a lot, but they are doing the opossite i want, they are using a list in PyQt and put it in a Maya UI. But yeah is almost the same – Alfredo Díaz Jun 03 '13 at 14:53
0

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)