[SOLVED] How to expand QVBoxLayout inside the widget ?
-
The following example work well and layout object expand itself inside the widget
@
MainWindow::MainWindow()
{
QWidget *widget = new QWidget;
setCentralWidget(widget);myButton = new QPushButton("My Button", this); myButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); myButton->setAlignment(Qt::AlignCenter); QVBoxLayout *layout = new QVBoxLayout; layout->setMargin(5); layout->addWidget(myButton); widget->setLayout(layout); setWindowTitle(tr("Sample")); resize(400, 600);
}
@I will see a big button inside the layout inside the widget (perfect)
Problem
If I generate the button and the layout from graphical environment the result is different.
The button expand itself inside the layout, but the layout don't expand itself inside the widget.
In this case the cose is the following:
@
MainWindow::MainWindow()
{
ui->setupUi(this);
setCentralWidget(ui->centralWidget);setWindowTitle(tr("Sample")); resize(400, 600);
}
@Does anyone know the solution?
-
Do not create the layout yourself. Add your button, then right-click on the main window and select Lay out -> Vertical.
-
Perfect, now it work.
Thank you.