[review] [PyKDE] Removing tabs from QTabWidget

Jim Bublitz jbublitz at nwinternet.com
Fri Oct 17 10:09:01 BST 2003


On Thursday October 16 2003 21:58, Trevor Phillips wrote:
> On Friday 17 October 2003 01:12, you wrote:
> > On Wednesday October 15 2003 23:21, Trevor Phillips wrote:
> > > At the moment I'm setting the current page to 0, and then
> > > while there's a current page, calling removePage. I've
> > > read, though, that this just hides the page, and doesn't
> > > deallocate it in memory. Is this an issue in the python
> > > implementation?
> >
> > Wouldn't it be easier just to destroy the entire QTabWidget
> > and recreate it? I'm not sure if you'd still need to delete
> > the page objects manually - I'm guessing you'd have to, but
> > haven't tried it.
>
> I've considered that, and may well do so. It's just neater if
> I can just redo the tabs themselves, since the overall
> properties of the tab set remain the same.
>
> BTW: How DO you destroy a widget? (Still very new to this...
> ^_^)

If you do:

    self.btn3 =  QPushButton ("btn3", self)
    ...
    del self.btn3

the parent widget effectively holds a reference to self.btn3, so 
the button really isn't deleted (although the Python symbol will 
be undefined). Making it 'btn3' and letting it go out of scope 
is effectively the same, as would be using 'btn3' as the name 
for all three buttons.

To really get rid of it you can try either

   self.removeChild (self.btn3)
   del self.btn3

or:
    self.btn3.reparent (None, QPoint (0, 0))
    del self.btn3

In your case, QTabWidget keeps pages in a separate dict (as well 
as in the QTabWidget's child list), so using removePage will 
cause the page to NOT display because it's been removed from the 
dict. But as you note, it doesn't destroy the page. QTabWidget 
still holds the page in it's child list, just as above.

removeChild seems more "correct" to me, but I've had problems 
with is causing segfaults in the past. I'm not sure if 
'reparent' ever segfaults, but in looking at some old code, I 
seem to have had some problems with it too (for a more complex 
widget - I manually deleted all of the widget's children before 
reparenting).

Hopefully someone knows more about this than I do. Please post if 
you do. I'm probably missing something obvious.

Jim




More information about the PyQt mailing list