замена макета на QWidget другим макетом

У меня есть виджет, который изменяется при переключении опции. Это делает недействительными все макеты и виджеты. Я храню список всех макетов, поэтому я могу удалить их, используя что-то похожее наэтот ответ:

<code>class MyWidget(QFrame):
   # ...
   def reLayout(self):
      def deleteLayoutChilds(l):
         while l.count():
            item=l.takeAt(0)
            widget=item.widget()
            if widget: widget.deleteLater()
            else: deleteLayoutChilds(item.layout())
      for l in self.allLayouts: deleteLayoutChilds(l)

      # now install the new layout
      ##
      ## how to delete the old layout first?
      l=self.layout(); del l # no effect
      #
      layout=QGridLayout(self)
      ## warning: QLayout: Attempting to add QLayout "" to MyWidget "", which already has a layout.
</code>

Как я могу избавиться от старого макета и установить новый?

Документация естьдовольно кратко и, видимо, не имеет прямого отношения к питону:

QWidget.setLayout (self, QLayout)

The QLayout argument has it's ownership transferred to Qt.

Sets the layout manager for this widget to layout.

If there already is a layout manager installed on this widget, QWidget won't let you install another. You must first delete the existing layout manager (returned by layout()) before you can call setLayout() with the new layout.

If layout is the layout manger on a different widget, setLayout() will reparent the layout and make it the layout manager for this widget.

Example:

<code> QVBoxLayout *layout = new QVBoxLayout;
 layout->addWidget(formWidget);
 setLayout(layout);
</code>

An alternative to calling this function is to pass this widget to the layout's constructor.

The QWidget will take ownership of layout.

See also layout() and Layout Management.

Ответы на вопрос(1)

Ваш ответ на вопрос