Rajeshwar Rajeshwar - 4 months ago 25
C++ Question

Hiding a vertical layout programatically?

I wanted to know if its possible to hide a vertical layout. I currently have a a horizonatal layout with two vertical layouts.I wanted to hide one of the vertical layouts(with all its content) on button click. Any suggestions on how I could do that.

jmk jmk

Instead of inserting vertical layouts directly into your top-level horizontal layout, use container widgets to easily control visibility:

// Create your left and right widgets
QWidget* leftWidget = new QWidget();
QVBoxLayout* leftLayout = new QVBoxLayout(leftWidget);
QWidget* rightWidget = new QWidget();
QVBoxLayout* rightLayout = new QVBoxLayout(rightWidget);

// Populate your vertical layouts here ...

QHBoxLayout* horizontalLayout = new QHBoxLayout(parentWidget);

Then, you can simply hide or show leftWidget or rightWidget to effectively control the visibility of everything in the vertical layouts that you have, without having to hide/show each individual widget.