Looping over widgets inside widgets inside layouts
<p>Similar question to what we have here <a href="http://stackoverflow.com/questions/5150182/loop-over-widgets-in-pyqt-layout">Loop over widgets in PyQt Layout</a> but a bit more complex...</p>

<p>I have</p>

<pre><code>QVGridLayout
   QGroupBox
      QGridLayout
         QLineEdit
</code></pre>

<p>I'd like to access QLineEdit but so far I dont know how to access children of QGroupBox</p>

<pre><code>        for i in range(self.GridLayout.count()):
            item = self.GridLayout.itemAt(i)
            for i in range(item.count()):
                lay = item.itemAt(i)
                edit = lay.findChildren(QLineEdit)
                print edit.text()
</code></pre>

<p>Can any1 point me to right dirrection?</p>

<p>When a widget is added to a layout, it automatically becomes a child of the widget the layout it is set on. So the example reduces to a two-liner:</p>

<pre><code>for group in self.GridLayout.parentWidget().findChildren(QGroupBox):
    for edit in group.findChildren(QLineEdit):
        # do stuff with edit
</code></pre>

<p>However, <code>findChildren</code> is <em>recursive</em>, so if all the line-edits are in group-boxes, this can be simplified to a one-liner:</p>

<pre><code>for edit in self.GridLayout.parentWidget().findChildren(QLineEdit):
    # do stuff with edit
</code></pre>

python pyqt qgroupbox