Results 1 to 3 of 3

Thread: Trouble with widgets resizing

  1. #1
    Join Date
    Jan 2011
    Posts
    55
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Trouble with widgets resizing

    Hi, I'm getting mad trying to solve this issue.
    I'm developing an application and the interface is organized like this:

    mainWindow(QWidget) -> vLayout(QVBoxLayout) -> myTabWidget(QTabWidget) -> myTab1(QWidget) -> myGridLayout(QGridLayout) -> redFrame,blueFrame,greenFrame,yellowFrame(QFrame)

    This is the code:

    Qt Code:
    1. mainWindow = new myMainWindow(); // instancing QWidget in a separate class
    2.  
    3. QVBoxLayout *vLayout=new QVBoxLayout(mainWindow);
    4. myTabWidget = new QTabWidget();
    5. vLayout->addWidget(myTabWidget);
    6.  
    7. myTab1 = new QWidget();
    8. myTabWidget->addTab(myTab1, QString());
    9.  
    10. blueFrame = new QFrame(myTab1); // blueFrame
    11. yellowFrame=new QFrame(myTab1); // yellowFrame
    12. QFrame *redFrame=new QFrame(myTab1); // redFrame
    13. greenFrame=new QFrame(myTab1); // greenFrame
    14.  
    15. QGridLayout *myGridLayout= new QGridLayout();
    16. myGridLayout->addWidget(redFrame,0,0);
    17. myGridLayout->addWidget(blueFrame,0,1);
    18. myGridLayout->addWidget(yellowFrame,1,0);
    19. myGridLayout->addWidget(greenFrame,1,1);
    20.  
    21. myTab1->setLayout( myGridLayout );
    To copy to clipboard, switch view to plain text mode 

    The application starts ok and all controls are displayed correctly (see first image).
    The issue I'm having is that when I resize the window, everything goes "berserk" (see second image) and the application eventually crashes. I think I'm doing an improper use of the layouts. Could somebody be so kind to help? Thanks again.

    ok.jpgko.jpg

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Trouble with widgets resizing

    There's only one item in the vertical layout, so that might be unnecessary. We cannot see how that layout is used in the enclosing window, or how you are enforcing the uneven space allocation that we see in the screen shots (the four frames in your example would be equally sized).

    Perhaps you could post a small, complete program that breaks in this way.

  3. #3
    Join Date
    Jan 2011
    Posts
    55
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Trouble with widgets resizing

    Hi Chris, thanks for your reply. After studying the code a little more, I realized I did something stupid in the overloaded resizeEvent for the main window.
    There, I called an instruction to force resizing so that the window sizes were constrained:

    resize(height()+220,height());

    That triggered an infinite loop, resizing over resizing, with the crazy effect displayed in the screenshot.
    I yet have to find a way to actually force a widget to mantain an aspect ratio, so that when the main window is resized, one or more widget aspect ratios are maintained.

Similar Threads

  1. Trouble resizing QDockWidget buttons with style sheet
    By Jon Heron in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2012, 02:41
  2. Replies: 0
    Last Post: 13th October 2010, 20:28
  3. resizing widgets in scroller
    By mike b in forum Newbie
    Replies: 0
    Last Post: 19th May 2010, 01:35
  4. Automatic resizing of child widgets
    By JovianGhost in forum Newbie
    Replies: 3
    Last Post: 11th March 2010, 12:47
  5. resizing widgets when user resizes mainwindow
    By Mystical Groovy in forum Qt Programming
    Replies: 13
    Last Post: 21st December 2009, 00:03

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.