Results 1 to 3 of 3

Thread: QMainWindow size policy

  1. #1
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QMainWindow size policy

    How it works?
    I create a simple Widget, apply setFixedSize to that widget and put it as the central widget of a MainWindow and... the widget size is changed to 480x480!
    I can't understand how it works and how I could make something as simple as asking the main window to just size itself so as to contain the child widget!
    Sizing is soooooo complicated in Qt!

  2. #2
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindow size policy

    Hi,

    If you use central widget, the window take ownership of the widget, meaning that the widget will fit the whole size of the window. If you want to resize your widget so resize the window with setGeometry(). If you want a widget that fits almost the whole area of your widget use layouts.

    Sizing is not complicated in QT. Its very easy, it just follows a different philosophy.

  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: QMainWindow size policy

    Quote Originally Posted by Caius Aérobus View Post
    How it works?
    Size policy only works when a widget is inside a layout. Since your main window is a window, it is not inside any layouts so its size policy is ignored.

    I can't understand how it works and how I could make something as simple as asking the main window to just size itself so as to contain the child widget!
    Set a size constraint on the layout managing the widget you wish to control the size of its parent.
    Qt Code:
    1. mainWindow()->layout()->setSizeConstraint(QLayout::SetFixedSize);
    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.


Similar Threads

  1. QDockWidget size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2011, 16:08
  2. QPlainTextEdit and its size policy
    By Lykurg in forum Qt Programming
    Replies: 0
    Last Post: 9th March 2010, 09:40
  3. Keep aspect size policy?
    By brcain in forum Qt Programming
    Replies: 2
    Last Post: 21st April 2009, 17:18
  4. QScrollView size policy?
    By Henrikas[MI] in forum Qt Programming
    Replies: 1
    Last Post: 19th November 2006, 10:52
  5. QMenuBar size policy
    By krivenok in forum Qt Programming
    Replies: 3
    Last Post: 16th January 2006, 15:13

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.