Results 1 to 12 of 12

Thread: How to change QMainWindow size at runtime?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default How to change QMainWindow size at runtime?

    Since there was no chance to determine the size of main window at very beginning, I have to change it later, at runtime.

    Basically my main window contained a toolbar, menu bar, as well as status bar. Then
    when the first child widget (will be central widget of main window) was created, it's best chance for me to adjust the size.

    The code liked below,

    Qt Code:
    1. // first set child widget geometry
    2. setGeometry(rect);
    3.  
    4. // adjust main window accordingly
    5. mainWnd->setCentralWidget(this);
    6. mainWnd->adjustSize();
    7.  
    8. // I also tried below
    9. // mainWnd->updateGeometry();
    To copy to clipboard, switch view to plain text mode 
    Besides, I've overridden sizeHint() of main window to return a QSize(0, 0), since it said if sizeHint() returned an invalid value, adjustSize() would set the size to the children rectangle that covers all child widgets.

    However, the resulting size of main window was totally too small than I expected.
    I'm really confused how Qt size policy was working.

    Could anyone help me?
    Thx.
    Last edited by high_flyer; 6th January 2011 at 10:35. Reason: code tags

Similar Threads

  1. QToolbar - change icon at runtime ?
    By pl01 in forum Qt Programming
    Replies: 6
    Last Post: 18th November 2010, 18:51
  2. Change QPixmap image at runtime
    By Qt Coder in forum Qt Programming
    Replies: 12
    Last Post: 30th March 2009, 13:37
  3. Replies: 2
    Last Post: 23rd March 2009, 18:26
  4. how change language at runtime?
    By mattia in forum Newbie
    Replies: 3
    Last Post: 14th November 2007, 19:36
  5. change font size and button size of QMessageBox
    By nass in forum Qt Programming
    Replies: 6
    Last Post: 13th September 2006, 20:16

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
  •  
Qt is a trademark of The Qt Company.