Try setting the size constraint on the top widget's layout to SetFixedSize. The widget will then grow or shrink depending on what its layout needs.
Try setting the size constraint on the top widget's layout to SetFixedSize. The widget will then grow or shrink depending on what its layout needs.
By top widget, I assume you mean the MainWindow. I tried it but it didn't work. A test project is attached to the first post of this thread.
Here is the current layout:
resize2..JPG
Last edited by schnitzel; 26th May 2010 at 17:08. Reason: fix layout
Not the size policy but size constraint of the layout. Scroll down until you see properties of the layout. You may also have to do the same for the layout of the central widget.
I tried changing the layout size constraints. Since there are three layouts in my test form, I tried different combinations setting layoutsizeconstraint to SetFixedSize and SetMinimumSize, but it still doesn't work. Are you able to make it work in the test project? I must be doing something else wrong.
You probably have to set the size constraint for the layout of the main window. You can't do it from within Designer, you have to code it manually in your project.
Qt Code:
#include <QtGui> public: for(int i=0;i<3;++i) x = 0; startTimer(2000); } protected: if(++x==7) killTimer(e->timerId()); } private: QVBoxLayout *l; int x; }; int main(int argc, char **argv){ QMainWindow mw; Widget *w = new Widget; mw.setCentralWidget(w); mw.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
mnunberg (19th September 2010)
Hi wysota,
I tried your suggestion and it works somewhat in the test app - 'somewhat' because now I can't resize it any more. My actual problem is more like this post. Hiding vs. removing the widgets from the layout can be thought of as equivalent - or so I thought.
With my test app I was trying to mimic what is going on in my actual application.
Sometimes it is difficult to describe subtle visual behavior in GUI applications.
I designed my application's GUI in Qt Creator's designer and numerous widgets that I have placed are being made invisible at run time - yet the space they have initially occupied is still shown but of course is empty. That is the problem I was trying to solve. The entire thing is not a deal breaker as the main form can simple be made smaller by resizing it manually by clicking and dragging the border after the application starts. I was just hoping for a nice programmatical solution.
Thanks for looking into this and I'm sorry if I wasted your time.
There is no sane way of adjusting the window size automatically and keeping the ability of resizing the window. Think what should happen if you resize the window manually and then an element gets hidden - should the window adjust its size (because an element was hidden) or retain it (because you resized it manually)? You can't eat the cake and keep the cake. You can program it manually but whichever behaviour you choose the other one will not work. You can try different size constraints but none of them will do exactly what you expect to achieve.
Bookmarks