I have a .ui mainwindow made with Design that have 3 images in a vertical layout. I made two others layout, horizontal and square, that use code to change the screen instead of Design. The problem, as seen in the image, is that when the layout is changed the views don't get resized correctly. They should have each 1/3 of the screen but one is big and the others small.

Captura de tela 2014-08-14 21.37.42.jpgCaptura de tela 2014-08-14 21.38.07.jpg

If I keep clicking on the horizontal layout button on the left, the views get resized just a bit until they are the correct size.

Here's the code I use to change layouts:

Qt Code:
  1. void MainWindow::setHorizontalLayout() // layout horizontally
  2. {
  3. ui->canvas->layout()->removeWidget(ui->graphicsView0);
  4. ui->canvas->layout()->removeWidget(ui->graphicsView1);
  5. ui->canvas->layout()->removeWidget(ui->graphicsView2);
  6. ui->canvas->layout()->removeWidget(ui->graphicsView3);
  7. ui->canvas->layout()->removeWidget(ui->frame0Controls);
  8. ui->canvas->layout()->removeWidget(ui->frame1Controls);
  9. ui->canvas->layout()->removeWidget(ui->frame2Controls);
  10. ui->canvas->layout()->removeWidget(ui->frame3Controls);
  11. delete ui->canvas->layout();
  12.  
  13. QGridLayout *horizontalLayout = new QGridLayout;
  14. horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
  15. ui->canvas->setLayout(horizontalLayout);
  16. horizontalLayout->addWidget(ui->view0Label, 0, 0);
  17. horizontalLayout->addWidget(ui->graphicsView0, 1, 0);
  18. horizontalLayout->addWidget(ui->frame0Controls, 2, 0);
  19. horizontalLayout->addWidget(ui->view1Label, 3, 0);
  20. horizontalLayout->addWidget(ui->graphicsView1, 4, 0);
  21. horizontalLayout->addWidget(ui->frame1Controls, 5, 0);
  22. horizontalLayout->addWidget(ui->view2Label, 6, 0);
  23. horizontalLayout->addWidget(ui->graphicsView2, 7, 0);
  24. horizontalLayout->addWidget(ui->frame2Controls, 8, 0);
  25. horizontalLayout->addWidget(ui->graphicsView3, 9, 0);
  26. horizontalLayout->addWidget(ui->frame3Controls, 10, 0);
  27. }
To copy to clipboard, switch view to plain text mode