Resizing qt widgets when their children are hidden

后端 未结 5 699
野趣味
野趣味 2020-12-31 05:13

How would I go about resizing the widget when the retry child is hidden so that it looks as in the first image? The main layout is a QVBoxLayout, the retry child is a widget

5条回答
  •  独厮守ぢ
    2020-12-31 05:30

    My problem was a little different in that I had a top-level QWidget (instead of a QDialog or a QMainWindow) that had children within a layout. When those children were resizing to larger, the QWidget would resize to accommodate, but not when they became SMALLER. Much like above, the area just had empty space. I finally found a solution:

    The layout used in my QWidget had a property called setSizeConstraint(). This is normally set to "QLayout::SetDefaultConstraint", which simply affects the "minimumSize" of the QWidget that owns it. Instead, I chose "QLayout::SetFixedSize" which made the layout adjust the fixed size of the owning QWidget, effectively making it SMALLER when it needed to be.

提交回复
热议问题