[PyQt] Completely removing items from a layout
missive at hotmail.com
Sat Nov 28 04:44:43 GMT 2009
I wrote about this a couple of weeks ago, but I did not have a small
working example to show the problem I'm having. Now I do.
I have a layout created in Qt4 Designer which I fill with a series of
complex layouts at runtime. That works great. Later on, I want
to completely remove all of them and fill it up again with a
The re-filling up part works fine, but the original set of items is
still visible and I can't work out how to get rid of them completely.
The code looks something like the following. Resize the window and
you will see a blob that is the leftovers from the first call to fillup()
from PyQt4 import QtGui
def setupUi(self, MainWindow):
self.centralwidget = QtGui.QWidget(MainWindow)
self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
# Represents a more complex layout to be placed inside verticalLayout
def __init__(self, name):
nm = QtGui.QLabel(name)
self.ui = Ui_MainWindow()
for name in [str(n) for n in range(10)]:
txt = name*20
# This is the troublesome one.
# How do I get rid of the contents of the layout completely?
vl = self.ui.verticalLayout
item = vl.itemAt(0)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
win = MainWindow()
# Thanks for any assistance
Windows Live Hotmail: Your friends can get your Facebook updates, right from Hotmail®.
More information about the PyQt