Deleting widgets from PyQt4 QFormWidget

A

Andrew

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
 
A

Andrew

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.
 
D

David Boddie

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 will remove the widget from the layout but it won't delete it because
it doesn't own it. The widget will still remain within its parent widget.
You have to either reparent it to another widget, or delete it manually.

[...]
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?

Try calling deleteLater() on each widget when you take it from the layout.
Does that work?

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top