Results 1 to 2 of 2

Thread: Change layout at runtime glitch?

  1. #1
    Join Date
    Mar 2014
    Posts
    7
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Question Change layout at runtime glitch?

    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 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Change layout at runtime glitch?

    That code is a bit of a contradiciton in naming.

    The method is called setHorizontalLayout(), but it creates grid layout and it adds the widgets in different rows, i.e. layouting them vertically.

    From your description and the screenshots I would guess that you want a QVBoxLayout, into which you add the control frames as-is and add the graphics views using the same stretch factor on each of the three calls.

    Cheers,
    _

Similar Threads

  1. DockWidgetArea change and layout direction change
    By mstegehu in forum Qt Programming
    Replies: 1
    Last Post: 21st February 2012, 22:24
  2. QToolbar - change icon at runtime ?
    By pl01 in forum Qt Programming
    Replies: 6
    Last Post: 18th November 2010, 18:51
  3. Change QPixmap image at runtime
    By Qt Coder in forum Qt Programming
    Replies: 12
    Last Post: 30th March 2009, 13:37
  4. Layout runtime customization
    By altVis in forum Qt Programming
    Replies: 3
    Last Post: 18th April 2008, 08:59
  5. how change language at runtime?
    By mattia in forum Newbie
    Replies: 3
    Last Post: 14th November 2007, 19:36

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.