Results 1 to 6 of 6

Thread: QMainWindow minimum size is much larger than the centralwidget inside it.

  1. #1
    Join Date
    Apr 2016
    Posts
    3
    Thanks
    1
    Qt products
    Platforms
    Windows

    Default QMainWindow minimum size is much larger than the centralwidget inside it.

    I am new to this forum (and new to PyQt).

    I have a QMainWindow which contains a QWidget (which is set to be the centralwidget, and it is the only widget there).
    The Qwidget has many widgets and layouts inside it, and all within one QVBoxLayout which is set to be the layout of the widget.
    One of the widgets is a QFrame which starts out hidden and contains some buttons and lists.

    At the startup the size of everything is fine. The Window is the correct size for containing the visible items.
    If I make the QFrame visible it expands the window vertically, which is what I wanted.
    But when I hide it again, the window does not shrink back to the original size (I tried the policies of Preferred, Expanding, and of MinimumExpanding)
    I can cause it to shrink a bit, by using the sizeHint of the Qwidget for both the QWidget and the QMainWindow.
    Manually I can change it back to the original size when it is running.
    I checked the sizeHint, and when hiding the QFrame it doesn't change for the QMainWindow (whereas, for the QWidget it does change to the correct value when the QFrame is hidden).
    Could my QMainWindow contain anything else besides the QWidget somehow?
    Or maybe sizehint for QMainWindow does not become smaller when possible? That still wouldn't explain why when I try to set the size of the QMainWindow within the code it doesn't work.

    Thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindow minimum size is much larger than the centralwidget inside it.

    It just doesn't automatically become smaller when you hide the frame.
    Just resize it manually once after hiding.

    Cheers,
    _

  3. #3
    Join Date
    Apr 2016
    Posts
    3
    Thanks
    1
    Qt products
    Platforms
    Windows

    Default Re: QMainWindow minimum size is much larger than the centralwidget inside it.

    Quote Originally Posted by anda_skoa View Post
    It just doesn't automatically become smaller when you hide the frame.
    Just resize it manually once after hiding.

    Cheers,
    _
    Thank you for the response. I see I wasn't clear in my statement. By manually, I meant that I had to use the mouse to drag the window size, and I couldn't find any code that would make it smaller. Using the sizehint of the internal QWidget made it a bit smaller, but not nearly the correct size, even though the sizehint of the QWidget is the correct size.

    Cheers!

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindow minimum size is much larger than the centralwidget inside it.

    Ah, I see.

    You can try to resize(0, 0)

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    erangre (14th April 2016)

  6. #5
    Join Date
    Apr 2016
    Posts
    3
    Thanks
    1
    Qt products
    Platforms
    Windows

    Default Re: QMainWindow minimum size is much larger than the centralwidget inside it.

    Thanks. With 0, 0 it made it too small, but then I realized I could save the size at startup, and then when needed set the minimum size to the startup size and the size to the minimum size. I am not sure if this is the "correct" way to do it, but it works.

  7. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QMainWindow minimum size is much larger than the centralwidget inside it.

    If you want to track the size hint of the contained widget always then look at the Fixed policy on the main window and a SetFixedSize on the layout of the contained widget. The Extension Example in the Qt docs might also help.

Similar Threads

  1. Access widget inside the QMainWindow centralwidget
    By graciano in forum Qt Programming
    Replies: 4
    Last Post: 23rd January 2014, 22:40
  2. QMainWindow central widget minimum size
    By dima in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2010, 08:24
  3. QMainWindow -> centralWidget size
    By lalesculiviu in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2009, 10:40
  4. Replies: 2
    Last Post: 23rd March 2009, 18:26
  5. Shrink QMainWindow to Minimum Size
    By kloffy in forum Qt Programming
    Replies: 4
    Last Post: 17th February 2008, 18:54

Tags for this Thread

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.