Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove widget from another Qwidget?

Tags:

qt

i created one QWidget(Parent). in the inside of the parent widget i created another one QWidget(Child). In the run time i need to remove the child widget. how to do that?

i am not using any layout. i am directly putting in the Parent Widget.

Please Help me to fix this.

like image 682
saravanan Avatar asked Oct 15 '10 05:10

saravanan


2 Answers

If you add the widget with e.g.:

QWidget *w = new QWidget(parent);

...then you can remove it with:

delete w;

Another approach would be to just hide it:

w->hide();
like image 144
sje397 Avatar answered Nov 10 '22 22:11

sje397


This answer is for those arriving from search engines and want an answer to the question as stated in the title.

If you want to remove a child from a parent without deleting it or hiding it (which does NOT remove it from its parent), set the child's parent to NULL.

QWidget::setParent(NULL)

Note that explicitly reparenting a widget like this carries several implications (e.g visibility automatically set to hidden). See QWidgets documentation for more information.

like image 26
Tenders McChiken Avatar answered Nov 10 '22 21:11

Tenders McChiken