Results 1 to 13 of 13

Thread: main window resize question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: main window resize question

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: main window resize question

    Quote Originally Posted by wysota View Post
    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

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: main window resize question

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: main window resize question

    Quote Originally Posted by wysota View Post
    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: main window resize question

    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:
    1. #include <QtGui>
    2.  
    3. class Widget : public QWidget {
    4. public:
    5. Widget() : QWidget() {
    6. l = new QVBoxLayout(this);
    7. for(int i=0;i<3;++i)
    8. l->addWidget(new QPushButton);
    9. x = 0;
    10. startTimer(2000);
    11. }
    12. protected:
    13. void timerEvent(QTimerEvent *e){
    14. l->addWidget(new QPushButton);
    15. if(++x==7) killTimer(e->timerId());
    16. }
    17. private:
    18. int x;
    19. };
    20.  
    21. int main(int argc, char **argv){
    22. QApplication app(argc, argv);
    23. mw.layout()->setSizeConstraint(QLayout::SetFixedSize);
    24. Widget *w = new Widget;
    25. mw.setCentralWidget(w);
    26. mw.show();
    27. return app.exec();
    28. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    mnunberg (19th September 2010)

  7. #6
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: main window resize question

    Quote Originally Posted by wysota View Post
    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.
    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.

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: main window resize question

    Quote Originally Posted by schnitzel View Post
    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.
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following 2 users say thank you to wysota for this useful post:

    Ishmael (3rd June 2010), schnitzel (27th May 2010)

  10. #8
    Join Date
    May 2010
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Smile Re: main window resize question

    Quote Originally Posted by wysota View Post
    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.
    You should use adjustResize() function in your application which set the size hint of application.
    i have done the same way.it is working

Similar Threads

  1. Resize main window after hiding an element
    By Swankee in forum Newbie
    Replies: 2
    Last Post: 22nd February 2012, 23:23
  2. Replies: 9
    Last Post: 16th May 2010, 16:21
  3. Replies: 11
    Last Post: 11th August 2008, 09:14
  4. Replies: 15
    Last Post: 23rd March 2007, 16:16
  5. Main window
    By Michiel in forum Qt Tools
    Replies: 1
    Last Post: 20th March 2006, 23:54

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.