PDA

View Full Version : Trouble with widgets resizing



papillon
9th August 2012, 01:02
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:



mainWindow = new myMainWindow(); // instancing QWidget in a separate class

QVBoxLayout *vLayout=new QVBoxLayout(mainWindow);
myTabWidget = new QTabWidget();
vLayout->addWidget(myTabWidget);

myTab1 = new QWidget();
myTabWidget->addTab(myTab1, QString());

blueFrame = new QFrame(myTab1); // blueFrame
yellowFrame=new QFrame(myTab1); // yellowFrame
QFrame *redFrame=new QFrame(myTab1); // redFrame
greenFrame=new QFrame(myTab1); // greenFrame

QGridLayout *myGridLayout= new QGridLayout();
myGridLayout->addWidget(redFrame,0,0);
myGridLayout->addWidget(blueFrame,0,1);
myGridLayout->addWidget(yellowFrame,1,0);
myGridLayout->addWidget(greenFrame,1,1);

myTab1->setLayout( myGridLayout );


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.

81108109

ChrisW67
9th August 2012, 03:08
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.

papillon
9th August 2012, 11:47
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.