'How to force force update of layout in qt, after calling sizePolicy().setVerticalStretch(...)

Using qt in python, I would like to dynamically alter the vertical stretch applied to two frames stacked vertically inside another container widget.

Based on reading a few things I came up with this solution, but it has no effect on the window at all.

def toggle_focus_mode(self):
    self.focus_mode = not self.focus_mode
    parent: QWidget = self.frame_top.parent()  # also frame_bottom's parent

    if self.focus_mode:
        print("Entering focus mode")
        self.frame_top.sizePolicy().setVerticalStretch(5)
        self.frame_bottom.sizePolicy().setVerticalStretch(2)
    else:
        print("Leaving focus mode")
        self.frame_top.sizePolicy().setVerticalStretch(2)
        self.frame_bottom.sizePolicy().setVerticalStretch(5)

    parent.layout().invalidate()
    self.frame_top.layout().invalidate()
    self.frame_bottom.layout().invalidate()
    parent.updateGeometry()
    self.frame_top.updateGeometry()
    self.frame_bottom.updateGeometry()

Changing the vertical stretch when creating the form works fine, I just can't get it to work after the window is shown.

I am stumped, any ideas regarding this scenario?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source