Deleting widgets from PyQt4 QFormWidget

Andrew andrewt.herd at gmail.com
Wed Sep 15 18:53:50 CEST 2010


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



More information about the Python-list mailing list