title: Clearing a Layout in Qt
body: <p>I'm creating an application in Qt that allows users to drag around various "modules" in a QGraphicsView. Whenever one of these modules is selected, it emits a signal which is then picked up by a "ConfigurationWidget" which is a side-panel which should display all of the relevant parameters of the selected module:  </p>
  
  <pre><code>class ConfigurationWidget : public QWidget
  {
    Q_OBJECT
  
    public:
      ConfigurationWidget(QWidget *parent) : QWidget(parent) {}  
  
    public slots:
      void moduleSelected(Module* m)
      {
        if(layout())
        { 
          while (itsLayout-&gt;count()&gt;0) 
          { 
            delete itsLayout-&gt;takeAt(0); 
          }
        }
        delete layout();
  
        itsLayout = new QFormLayout(this);
        itsLayout-&gt;addRow(QString(tr("Type:")),     new QLabel(m-&gt;name()));
        itsLayout-&gt;addRow(QString(tr("Instance:")), new QLabel(m-&gt;instanceID()));
        // ... Display a whole bunch of other fields that depends on the module
      }
  };
  </code></pre>
  
  <p>The problem is that the ConfigurationWidget never actually gets cleared when a module is selected. The new fields are just drawn over the old ones. I've tried various combinations of hide() and show(), invalidate(), update(), etc. to no avail.</p>
  
  <p>What's the correct way to make a widget that can change its fields like this on the fly?</p>