PDA

View Full Version : resizing widgets when user resizes mainwindow



Mystical Groovy
19th December 2009, 12:24
Hello all,

I'd like when the user resizes the main window of my app, the widgets inside the main window to be resized automatically too.

Ive set the sizePolicy of my main window to preferred.
all the widgets inside the main window are placed inside a tab widget which is under the centralWidget.

this is what ive tried so far:



/* i suppose that when the user resizes the window, the height changes so i tried to check it with the following : */
if(!minimumSize().height == 800) //where 800 is the default height for the window
{
tabwidget->updateGeometry();
// centralWidget->updateGeometry();
// setupUi(this);
}

i hope you get the meaning,
any help is appreciated

Lykurg
19th December 2009, 13:43
Use layouts, then you don't have to do the children resizing by your own: QLayout, QGridLayout...

franco.amato
19th December 2009, 13:51
Use layouts, then you don't have to do the children resizing by your own: QLayout, QGridLayout...

Lykurg I'm trying to do the same but seems impossible for me to get good results. I'm becoming crazy.
Can you help me please?
I can send you some code

Best

Mystical Groovy
19th December 2009, 14:09
EDITED

ive tried to lay my widget under a grid layout, for some strage reason the app compiled and run ok but i lost connection with my .cpp file, for ex i clicked on a button on my app and nothing happened! lol, when i removed the grid layout everything worked correctly again :P..

ive also tried to right click to my tabwidget and lay out as grid layout, but then i couldnt setup the widgets where i want them to be in the form.. lol...

so lets forget the layout method, i dont have a problem to code all of my widgets in the app to resize automatically as long as i know how to do it...

so please help hehe xD

Lykurg
19th December 2009, 14:20
Using QLayout correct don't break any functionality! Let me see some code and I might tell you the error... Just post it here.

Mystical Groovy
19th December 2009, 14:25
hi and thx for the reply :)
well basically im doing all the form work using the QtCreator's intergrated designer, so i dont have a spesific laying out widgets code on my source file.

I could try to lay my widget in a QLayout using code if this is necessary (im trying to avoid setting up the widgets again via code coz it'll take ages you see ) :)

Mystical Groovy
19th December 2009, 14:29
oh!, i have some button that to be shown, they'll have to be triggered first not done with the designer and layeded out on a QVBoxLayout and QHBoxLayout, maybe thats why it breaks the functionality?



vbox = new QVBoxLayout;
vbox->addWidget(pkgdesclbl);
vbox->addWidget(pkgdescText);
vbox->addWidget(pkgfilelistlbl);
vbox->addWidget(pkgfilelistText);
vbox->addWidget(consoleOutlbl);
vbox->addWidget(consoleOutText);

hbox = new QHBoxLayout(vbox);
hbox->addWidget(pkgsaveBtn);
hbox->addWidget(pkgcopyBtn);

pkginfoBox->setLayout(vbox); //this is a QFrame in my applications form

Mystical Groovy
19th December 2009, 15:39
well i managed to lay out the tabwidget in my main window and when i resize the main window the tabwidget resizes along but not the widgets under the tabwidget.

i tried to lay out the widgets inside the tabwidget but as before it messes up my widget potitions and i cant set them in the way i want...

Mystical Groovy
20th December 2009, 17:54
any help please?

wysota
20th December 2009, 18:18
any help please?

Sure. As soon as you post the code reproducing the problem or at least a screenshot of what you want to obtain.

Mystical Groovy
20th December 2009, 19:08
ok look, the problem is that i cant get the widgets inside tabwidget in my application resize along with the main window when the user resizes it.

first i tried to do this (as posted in the first post)

/* i suppose that when the user resizes the window, the height changes so i tried to check it with the following : */
if(!minimumSize().height == 800) //where 800 is the default height for the window
{
tabwidget->updateGeometry();
// centralWidget->updateGeometry();
// setupUi(this);
}

then Lykurg suggested to use layouts, but when i lay the widgets inside my tabwidget in a grid layout it messes the potition of the widgets up and i cant get them to where i want them to be shown.

wysota
20th December 2009, 19:17
That's why I ask you to post a screenshot (or better yet a ui file) and we'll help you place them in a layout. It's either that or doing the layout manually by reimplementing resizeEvent() of each and every tab in your window. It's really much quicker to do it with layouts.

Mystical Groovy
20th December 2009, 20:03
here you go mate, thanks :)

wysota
21st December 2009, 01:03
Here you go. But I'd replace all those QToolButton instances with QPushButtons. Their size will adjust to the parent without the need to change the default size policy (I didn't change them on purpose so that you can see the difference).