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.