View Full Version : QBoxLayout removeWidget problem

30th August 2006, 02:30
I have a QBoxLayout and I want to delete some widget from it. That widget was created like this:

QWidget qw;

QComboBox combo=new QComboBox(&qw); //parent the principal widget
QComboBox combo2=new QComboBox(&qw);


With the last instruction the widget appears perfectly in the window, but when I try to remove it with
it doesn't work. The widget still appears in the window and I can interact with it.
So.. how can I remove this widget completly?


30th August 2006, 04:14
Finally I solved this doing a setParent(0); that way it is not painted anymore.

Chicken Blood Machine
30th August 2006, 07:13
You should have called hide() on the widget. setParent(0) will just make the widget into a toplevel widget (no parent). Look around carefully and no doubt it is floating around on your desktop somewhere (or it will after a show()).

30th August 2006, 21:57
QLayout::removeWidget() does only remove the widget from the layout so that it's geometry won't be anymore managed by the layout. The widget will be left there where it was during the removal. If you want to get completely rid of the widget, delete it. If you will need it later, hide it. Just be aware that reparenting it with no parent makes it just a top level widget as CBM already stated. That's most probably not what you want.