title: Removing QWidgets from a QGridLayout
body: <p>I have a <code>QGridLayout</code> where I add my custom <code>QWidgets</code>.</p>
  
  <p>When I try to delete all of them they are supposedly removed from the layout (as the function <code>layout.count()</code> returns 0) but they are still shown in the interface and I can interact with them.</p>
  
  <p>Here you have the way I add widgets:</p>
  
  <pre><code>void MyClass::addCustomWidget(CustomWidget *_widget, int r, int c)
  {
      layout-&gt;addWidget(_widget, r, c);
      _widget-&gt;show();
  }
  </code></pre>
  
  <p>And here the way I delete them:</p>
  
  <pre><code>void MyClass::clearLayout()
  {
      qDebug() &lt;&lt; "Layout count before clearing it: " &lt;&lt; layout-&gt;count();
  
      int count = layout-&gt;count();
      int colums = layout-&gt;columnCount();
      int rows = layout-&gt;rowCount();
  
      int i=0;
      for(int j=0; j&lt;rows; j++)
      {
          for(int k=0; k&lt;colums &amp;&amp; i&lt;count; k++)
          {
              i++;
  
              qDebug() &lt;&lt; "Removing item at: " &lt;&lt; j &lt;&lt; "," &lt;&lt; k;
              QLayoutItem* item = layout-&gt;itemAtPosition(j, k);
  
              if (!item) continue;
  
              if (item-&gt;widget()) {
                  layout-&gt;removeWidget(item-&gt;widget());
              } else {
                  layout-&gt;removeItem(item);
              }
              qDebug() &lt;&lt; "Removed!";
          }
      }
  
      qDebug() &lt;&lt; "Layout count after clearing it: " &lt;&lt; layout-&gt;count();
  }
  </code></pre>
  
  <p>Any kind of help or tip to delete items/widgets correctly from a QGridLayout?</p>
  
  <p><strong>P.D. :</strong> I have seen on the internet that a lot of people deletes the widget directly (delete _widget) after removing them from the layout. In my case it is not possible as I need to mantain that widgets in memory.</p>