[PyKDE] QScrollView - removeChild gives odd results...

Mark Newton newton_mark at hotmail.com
Thu Aug 24 12:06:19 BST 2000


Hi,

I'm trying to create a scrollview widget to which you can add or remove line 
edit (or other) widgets at run-time by pressing either an 'Add' button or a 
'Remove' button.
When the 'Add' button is pressed I create a line edit widget, call its 
show() method and then call addChild(widget, 0, 0) which makes the graphic 
appear in the viewport at location 0,0.
When the 'Remove' button is pressed I do the reverse; call 
removeChild(widget) then the hide() method of the line edit and finally 
delete the line edit using del. This makes the graphic disappear from the 
viewport.
I now hope to be back in my initial state however, if the 'Add' button is 
pressed again then a line edit appears but not as wide as the original.

Furthermore if I try to add/remove/add my own kind of widget (containing a 
couple of line edits and a label inside a QHBox) then this appears slightly 
offset from 0,0 in addition to being less wide.

Am I doing something wrong? I can't find any examples of using removeChild 
in either the Qt or PyQt examples....

Here is my code:

class SVTAB(QHBox):
  def __init__(self, parent=None, name=None):
    QHBox.__init__(self, parent, name)

    self.items=[]

    self.scrollView = QScrollView(self)
    self.buttonGroup = QButtonGroup(1, Qt.Orientation.Horizontal, self)   # 
Vertical & Horizontal swapped here :)
    self.add = QPushButton('Add', self.buttonGroup)
    self.remove = QPushButton('Remove', self.buttonGroup)

    # Set-up widgets
    self.scrollView.enableClipper(TRUE)

    # Connect signals
    self.connect(self.add, SIGNAL('clicked()'), self.addPath)
    self.connect(self.remove, SIGNAL('clicked()'), self.removePath)

  def addPath(self):
    print "Add path"
    self.items.append(envLineEdit(self.scrollView.viewport(), 'INTASDBNAME', 
4, 'hoohaa', '', FALSE))
    #self.items.append(QLineEdit(self.scrollView.viewport()))
    self.items[0].show()
    self.scrollView.addChild(self.items[0], 0, 0)
    print self.items

  def removePath(self):
    print "Remove path"
    self.scrollView.removeChild(self.items[0])
    self.items[0].hide()
    del self.items[0]
    print self.items

  def updateValues(self):
    for item in self.items:
      item.update()

Mark
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com





More information about the PyQt mailing list