Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove QWidgets from QSplitter

In my app have a window splitted by a QSplitter, and I need to remove an widget.

How can I do that? I can't find useful methods

like image 328
Giancarlo Avatar asked Dec 16 '08 15:12

Giancarlo


3 Answers

It's not clear to me if you want to preserve the widget and put it somewhere else, or if you want to destroy the widget.

  • Destroying the widget: If you can get a pointer to the widget, you can simply delete it. The splitter will safely be notified that its child is being deleted and will remove it from itself.

  • Preserving the widget: If you grab the pointer to the widget, you can simply set its parent to some other widget and add it to another widget's layout and it will show up there. This is safe because the QSplitter will be notified that one of its children is being reparented.

If you want to set the parent to NULL (cjhuitt's answer) be aware that you are now responsible for cleaning up that memory because the widget no longer has a parent.

like image 178
Michael Bishop Avatar answered Oct 15 '22 20:10

Michael Bishop


Many things in Qt cannot be "traditionally" removed. Instead call hide() on it and destruct it. From QSplitter documentation:

When you hide() a child its space will be distributed among the other children. It will be reinstated when you show() it again.

like image 17
Tuminoid Avatar answered Oct 15 '22 19:10

Tuminoid


I like Tuminoid's answer. But if you absolutely need it removed, try getting the widget you want to remove, and calling setParent( NULL ) on that widget. That's my best guess.

like image 2
Caleb Huitt - cjhuitt Avatar answered Oct 15 '22 18:10

Caleb Huitt - cjhuitt