[PyKDE] QScrollView - removeChild gives odd results...
Phil Thompson
phil at river-bank.demon.co.uk
Sun Aug 27 19:15:31 BST 2000
What version of Qt? What version of PyQt?
Phil
Mark Newton wrote:
>
> 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
>
> _______________________________________________
> PyKDE mailing list PyKDE at mats.gmd.de
> http://mats.gmd.de/mailman/listinfo/pykde
More information about the PyQt
mailing list