Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] How to expand QVBoxLayout inside the widget ?

[SOLVED] How to expand QVBoxLayout inside the widget ?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nologinma
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Do not create the layout yourself. Add your button, then right-click on the main window and select Lay out -> Vertical.

      (Z(:^

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nologinma
        wrote on last edited by
        #3

        Perfect, now it work.
        Thank you.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved