PyQt collapsible GroupBox or Layout

8,659 views
Skip to first unread message

Christian Akesson

unread,
Aug 30, 2010, 2:37:33 PM8/30/10
to python_in...@googlegroups.com
Really sorry to hit this group with a question regarding PyQt, but I know there is a lot of skillz in here that does not only pertains to pyMel.
I have grown very accustomed to Maya's collapsible frame layout functionality and having the collapse action recalculating and setting the window size. 

Transitioning over to (py)Qt, I was disappointed to find that nothing seems to be collapsible in Qt land (at least not according to my Google searches).
I actually need this functionality outside of Maya as well as in Maya, so I need to find a Qt solution and not a Maya solution.

Has anyone managed to get PyQt layouts, GroupBox (preferred) or anything to collapse and give space in the UI for more functionality?
Would really appreciate any pointers.

Thanks,
/Christian

James Robison

unread,
Aug 30, 2010, 8:45:05 PM8/30/10
to python_in...@googlegroups.com
You can create a signal between the value 'toggled(bool)' of the checkbox from a QGroupBox to the 'setVisible(bool)' of a QFrame, which will function like a collpasible area.

example attached.

cheers
James



collapseFrame.ui

Judah Baron

unread,
Aug 30, 2010, 8:20:23 PM8/30/10
to python_in...@googlegroups.com
You could subclass QWidget and add a collapse button that handles the problem by changing the size of your widget and possibly hiding the children.

-Judah


Christian Akesson

unread,
Aug 31, 2010, 6:38:20 PM8/31/10
to python_in...@googlegroups.com
Thanks for the replies guys.

Judah, I would be interested in this approach for a more complete approach, but I am not quite sure how to go about this or where to start. Would you have any good pointers?

I ended up with an interim solution for the time being using the checkbox of the QGroupBox. I found that object.sizeHint() is really nice as it tells you what width, height the object should be. I ended up setting the height so that it would work for anything inside the groupBox.
Added code example below...a bit hacky, but it works.

/Thanks
Christian

# Signal Connection
self.connect(self.aGroupBox, SIGNAL("clicked()"), lambda gBox = "self.aGroupBox": self.collapse(gBox))

def collapse(self, gBox):
""" Collapses a QGroupBox """
# Find out if the state is on or off
gbState = eval(gBox + '.isChecked()')
if not gbState:
eval (gBox + '.setFixedHeight(15)') 
                # Set window Height
self.setFixedHeight(self.sizeHint().height())
else:
oSize = eval(gBox + '.sizeHint()')
eval(gBox + '.setFixedHeight(oSize.height())')
                # Set window Height
self.setFixedHeight(self.sizeHint().height())
/Christian


liaoyong_idmt

unread,
Sep 3, 2010, 11:46:31 AM9/3/10
to python_inside_maya
are you ring is very ok?
 
 
2010-09-03

liaoyong_idmt

发件人: Christian Akesson
发送时间: 2010-09-01  06:38:36
收件人: python_inside_maya
抄送:
主题: Re: [Maya-Python] PyQt collapsible GroupBox or Layout
liaoyong_idmt@163.com.jpg
Reply all
Reply to author
Forward
0 new messages