Results 1 to 5 of 5

Thread: minimizing main window

  1. #1
    Join Date
    Nov 2007
    Posts
    57
    Thanks
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default minimizing main window

    Hi all! I was wondering if anybody could recommend how to always keep the main window (main layout) as minimal as possible for whatever it countains even if the size of its content changes.
    More specifically: My window size is not pre-determined. My window (main layout) contains a QLabel. So, first the window assumes a minimal size to accomodate the QLabel and that's what I want. As the program runs, the QLabels is getting smaller. Now I want the window to automatically contract to the smallest possible size but my window retains its original size. So far it can only expand, not contract. How do I make it contract? I guess I need to somehow refresh the main window but I don't know how.
    Always thankful for your ideas. eric

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: minimizing main window

    You can either call QWidget::adjustSize() by hand or if you're willing to make the window fixed size, you can do
    Qt Code:
    1. window->layout()->setSizeConstraint(QLayout::SetFixedSize);
    To copy to clipboard, switch view to plain text mode 
    and it will automatically follow size hint changes.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    eric (28th November 2007)

  4. #3
    Join Date
    Nov 2007
    Posts
    57
    Thanks
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: minimizing main window

    Thank you jpn!
    The below code still won't make the window to always assume the smallest size possible. I may have understood you wrong or maybe I should remove all the addStretch() lines from my constructor code?

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication application(argc, argv);
    4. MyWidget window;
    5. window.adjustSize();
    6. window.show();
    7. return application.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 

    I don't want to make the window fixed size, I'd like it to be collapsible.

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: minimizing main window

    You would have to call adjustSize() every time the size changes. This is what I meant with "by hand".
    J-P Nurmi

  6. #5
    Join Date
    Nov 2007
    Posts
    57
    Thanks
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: minimizing main window

    I got you, but I can't put the code
    Qt Code:
    1. window.adjustSize();
    To copy to clipboard, switch view to plain text mode 
    in the function (which is in a separate file) that causes the need for window resizing - the code won't compile. I get "not enough contextual info" error message. Apparently the other functions don't know what "window" is. Window is only declared in the main() function and is not part of my *.h file. Does "window" have to be in the *.h file in order for the above line to work? I don't think I could create "window" anywhere else than the main function?
    So you say that it is not possible to make the main function always check the size of the window and see if it could possibly be made smaller?

Similar Threads

  1. Background image for main window widget using css.
    By Enygma in forum Qt Programming
    Replies: 8
    Last Post: 23rd August 2007, 16:40
  2. Replies: 15
    Last Post: 23rd March 2007, 17:16
  3. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 09:41
  4. Replies: 5
    Last Post: 5th August 2006, 00:44
  5. cannot make a main window modal
    By Dark_Tower in forum Qt Programming
    Replies: 12
    Last Post: 23rd March 2006, 11:21

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.