Search code examples
qtuser-interfacelayoutqt5

How to make new widgets fill available space?


I am having some trouble making a new QT widget fill all the available space.

I want to add a widget (a QGLWidget) to the verticle layout (mVisual) and have the layout resize so that mVisual occupies the maximal amount of area.

My layout looks as follows:

enter image description here

The code I have is

ui.setupUi(this);
mWidget = new glStream();
//mWidget->setMinimumHeight(480);
//mWidget->setMinimumWidth(480);
ui.mVisual->addWidget(mWidget);

The problem is that if I don't manually set the width or height I can't even see my widget when I add it!

The only thing I can think of is to perform some sort or arithmetic like parentSize-lytControlsSize, but this feels dirty and like MFC.

How can I layout my widgets so that one layout (mVisual) is minimal, while the other is maximal?


Solution

  • If you put your widget in a Layout, widget fill all available space in their parent area, and if you want to fill without margins, set Layout margins to 0.