There is a layer with two buttons. Everything is created programmatically:

ui->setupUi(this); layout = new QVBoxLayout(this); setLayout(layout); for (int i(0); i < (list.size() + 1); i++){ QPushButton *button = new QPushButton(this); layout->addWidget(button); } lGeometry.setRect(281, 314, 650, 460);/ layout->setObjectName("mainLayot"); layout->setGeometry(lGeometry); qDebug() << layout->geometry(); 

When you start the program, the layer still opens to the entire widget, and qDebug() :

QRect (0.0 824x557)

Tried to use the layout->setSizeConstraint(QLayout::SetFixedSize); but then everything is minimized to both the main widget and the layer and buttons. Tell me how to be?

    2 answers 2

    Why set the size of the Layout? Set the dimensions and geometry of the QWidget , and install a Layout into it. Layout will occupy all the free space of the widget and you will get what you are looking for.

    • Yes, that's the problem, that I don't need him to occupy all the free space. And I would like it to be in the middle at a clearly indicated point. Noah already found out that this is not done. It is necessary to equate everything with spacers and stretches. - Madisson
    • @Madisson, so I’m telling you - place a widget at this point, and stick a layout into it. - ixSci Sep.

    I decided this way: I made a QVBoxLayout, I was pushed into it by a widget that contains the required Layout. At the expense of the widget, you can edit a clear size, and at the expense of the external Layout, alignment.