Delete subclass in qt?

In PyQt 4.5, I have a layout inside another layout. I would like to remove the sublayout from my parent and hide it. I can say to parent_layout.removeItem(child_layout)remove the layout from my parent, but it still appears in the widgets. I can’t find a way to hide it in one step, since it QLayoutdoesn’t have a method hide(), for example QWidget.

+3
source share
2 answers

A simple solution would be to have an internal widget, not an internal layout. You can assign the layout you want for the widget, and then simply remove / hide the widget when you want to do this. A good rule of thumb is that you just want to arrange your widgets and then use the layout; if you want to hide / show them as a group, use the widget.

+4
source

With some help flupke on, #qtI came up with:

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

It is assumed that all child layouts are widgets. Is there a simpler solution?

+1
source

Source: https://habr.com/ru/post/1724697/


All Articles