title: Remove all items from a layout
body: <p>I was trying to find something that would take a qt layout and delete everything from it. Just to imagine what the window looks like - I have: </p>
  
  <pre><code>QVBoxLayout
       | ------QHboxLayout
                   |---------QWidget
       | ------QHboxLayout
                   |---------QWidget
              .........
  </code></pre>
  
  <p>So I need something that I can call recursively to CLEAR AND DELETE all the stuff from my parent <code>QVBoxLayout</code>. I tried things mentioned here (<a href="https://stackoverflow.com/questions/4528347/clear-all-widgets-in-a-layout-in-pyqt">Clear all widgets in a layout in pyqt</a>) but none of them work (no correct answer marked anyway). My code looks like this:</p>
  
  <pre><code>def clearLayout(self, layout):
      for i in range(layout.count()):
          if (type(layout.itemAt(i)) == QtGui.QHBoxLayout):
              print "layout " + str(layout.itemAt(i))
              self.clearLayout(layout.itemAt(i))
          else:
              print "widget" + str(layout.itemAt(i))
              layout.itemAt(i).widget().close()
  </code></pre>
  
  <p>But it gives an error:</p>
  
  <pre><code>               layout.itemAt(i).widget().close()
              AttributeError: 'NoneType' object has no attribute 'close'
  </code></pre>
  
  <p>=>EDIT
  This kinda works (but doesn't if there is any other <code>Layout</code> than <code>HBoxLayout</code>:</p>
  
  <pre><code>def clearLayout(self, layout):
      layouts = []
      for i in range(layout.count()):
          if (type(layout.itemAt(i)) == QtGui.QHBoxLayout):
              print "layout " + str(layout.itemAt(i))
              self.clearLayout(layout.itemAt(i))
              layouts.append(layout.itemAt(i))
          else:
              print "widget" + str(layout.itemAt(i))
              if (type(layout.itemAt(i)) == QtGui.QWidgetItem):
                  layout.itemAt(i).widget().close()
  </code></pre>