[PyQt] cleaning up after removing items from layout
Lee Harr
missive at hotmail.com
Sun Nov 8 01:15:47 GMT 2009
<f9e39bbc0911071609w28004568j569698db8cd75c88 at mail.gmail.com>
Content-Type: text/plain; charset="windows-1256"
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0
> Could you post the whole code in py file?
The actual code is here:
http://code.google.com/p/pybotwar/source/browse/qt4view.py
The item that is getting added is the class at line 362.
And the method that tries to remove the original items
is at line 172.
I also made a small example of the problem...
repop.ui is a QMainWindow made with Qt Designer that has
a VBoxLayout laid out with a horizontal spacer horizontally
then laid out with a vertical spacer vertically.
It does not show exactly the same behavior. When this is run,
you can see a blotch where all of the items get written over
one another the 2nd time through.
# repop.py
import os
import sys
from PyQt4 import QtCore, QtGui, uic, QtSvg
from PyQt4.Qt import QHBoxLayout
uidir = 'data/ui'
class RP(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
uifile = 'repop.ui'
uipath = os.path.join(uidir, uifile)
RPClass, _ = uic.loadUiType(uipath)
self.ui = RPClass()
self.ui.setupUi(self)
self.pop()
self.repop()
def pop(self):
for n in range(10):
ri = RI(str(n))
self.ui.vl.addLayout(ri)
def repop(self):
vl = self.ui.vl
while vl.count():
item = vl.itemAt(0)
vl.removeItem(item)
self.pop()
class RI(QtGui.QHBoxLayout):
def __init__(self, name, rend=None):
QtGui.QHBoxLayout.__init__(self)
vl = QtGui.QVBoxLayout()
nm = QtGui.QLabel(name)
vl.addWidget(nm)
self.addLayout(vl)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
rp = RP()
rp.show()
app.exec_()
# end
Thanks for any suggestions.
_________________________________________________________________
Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail you.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010
More information about the PyQt
mailing list