PDA

View Full Version : hiding a widget without rearrange layout



mastupristi
6th July 2009, 16:33
I have 3 widget in a QHBoxLayout; when one of these is hidden, the layout is rearranged as if there is only two widget.
I need that the hidden widget is not shown but the layout is unchanged.
how can I obtain this behaviour?

thanks

wysota
6th July 2009, 17:20
You have two possible solutions.

One, easier is to subclass the widget and reimplement its paintEvent (and possibly some of the input events) and either call the base class implementation or not, depending on a state of some flag. If you don't call the base class implementation, you'll get an empty widget.

The other solution (which is probably more sane) is to put the widget into a QStackedWidget and add another empty widget to the stack. You just have to make sure the empty widget is of the same size as the real one (and it's size has to be fixed). Then all you need to do to "hide" a widget is to flip the page on the stack.