You cannot set a maximum size for QVBoxLayout . You will probably need to set the maximum size in the widgets that the layout contains. If you want one of the layouts to stretch and the other the same size, you can try the following in your mainwindow constructor:
QPushButton* btn1 = new QPushButton("Button1"); QPushButton* btn2 = new QPushButton("Button2"); QHBoxLayout* hLayout = new QHBoxLayout; QVBoxLayout* vLayout1 = new QVBoxLayout; QVBoxLayout* vLayout2 = new QVBoxLayout; hLayout->addLayout(vLayout1, 1); hLayout->addLayout(vLayout2, 0); vLayout1->addWidget(btn1); vLayout2->addWidget(btn2); QWidget* placeholder = new QWidget; placeholder->setLayout(hLayout); setCentralWidget(placeholder);
If you resize the window now, you will see a layout containing the stretch Button2 , while a layout containing Button1 will remain the same size.
source share