tags:

views:

306

answers:

2

In PyQt 4.5, I have a layout inside another layout. I'd like to remove the sublayout from its parent, and hide it. I can say parent_layout.removeItem(child_layout) to remove the layout from its parent, but it still shows on the widget. I can't find any way to hide it in one step, as QLayout doesn't have a hide() method like QWidget does.

A: 

With some help from flupke on #qt, I came up with:

for i in range(0, child_layout.count()):
  child_layout.itemAt(i).widget().hide()
parent_layout.removeItem(child_layout)

Which assumes all the child layout's children are widgets. Is there a simpler solution?

Andrew Magee
+2  A: 

The easy solution would be to have an interior widget, not an interior layout. You could assign the layout you desire to the widget, then just remove/hide the widget when you want to do so. A good rule of thumb is if you just want to arrange how widgets appear, then use a layout; if you want to hide/show them as a group, use a widget.

Caleb Huitt - cjhuitt