Deleting widgets from PyQt4 QFormWidget

Andrew andrewt.herd at
Wed Sep 15 19:10:11 CEST 2010

On Sep 15, 9:53 am, Andrew <andrewt.h... at> wrote:
> I'm trying to remove the widgets from the QFormLayout widget from
> PyQt4. According to the documentation I should be able to use the
> command .takeAt(int) which will delete the widget from the layout and
> then return to me the QLayoutWidget.
> It currently is giving me back the widget, but is not removing it from
> the layout.
> At the moment, I'm simply trying to clear out all the widgets on the
> layout with this:
> def clearForm(self):
>                 print ("Clearing")
>                 print self.dataForm.rowCount()
>                 for i in range(self.dataForm.rowCount()-1, -1, -1):
>                         print " .",
>                         tmp = self.dataForm.takeAt(i)
>                         print tmp.widget()
>                         tmp = ""
>                 print self.dataForm.rowCount()
> It goes through each widget on the layout, and prints out the
> classes .__repr__ on the tmp.widget() line since tmp is a
> QLayoutWidget. So it's doing the returning part, but they still exist
> instead of being deleted like the documentation explains.
> Am I missing a step or is this just broken? I haven't been able to
> find anything else on this issue yet. If it's broke, is there any
> potential workaround?
> I'm using python 2.6.4 and PyQt4 4.7.6
> Thanks,
> Andrew

QLayoutWidget, I meant a QWidgetItem.

More information about the Python-list mailing list