@thatbeatrice QLayoutItem::setAlignment() tells the layout item (widget or QLayoutItem subclass) where to put itself inside the space given to it by its parent layout. The middle layout is given the entire client area of the widget containing this code to manage. You are not putting your top or bottom layout items into a layout, so their position is entirely up to you to manage (and you are not).
These are two different options
#include <QApplication>
#include <QWidget>
#include <QLabel>
#include <QVBoxLayout>
#include <QGridLayout>
int main(int argc, char **argv) {
QApplication app(argc, argv);
QWidget w;
QLabel *top = new QLabel("Top Left", &w);
QLabel *mid = new QLabel("Middle right", &w);
QLabel *bot = new QLabel("Bottom right", &w);
#if 1
// Option 1
QVBoxLayout *layout = new QVBoxLayout(&w);
top->setAlignment(Qt::AlignLeft | Qt::AlignTop);
mid->setAlignment(Qt::AlignCenter);
bot->setAlignment(Qt::AlignLeft | Qt::AlignBottom);
layout->addWidget(top);
layout->addWidget(mid);
layout->addWidget(bot);
#else
// Option 2
QGridLayout *layout = new QGridLayout(&w);
layout->addWidget(top, 0, 0, Qt::AlignLeft | Qt::AlignTop);
layout->addWidget(mid, 1, 1, Qt::AlignCenter);
layout->addWidget(bot, 2, 0, Qt::AlignLeft | Qt::AlignBottom);
#endif
w.resize(800, 600);
w.show();
return app.exec();
}
Whether you want to use the code that Designer and uic produce, it can be very informative to see how it constructs things.