Setting minimum size on a widget triggers a resizing to content
-
I'm trying to figure out why and how to prevent a QDockWidget from resizing to content when setting minimumSize.
I have few QDockWidget with some other widgets inside and need to collapse them sometimes, basically macing them invisible. Setting visibility works but has the drawback that all shortcuts are disabled which is a problem. Now I'm setting fixed size to 0 when collapsing and resetting size, minimum and maximum size when uncollapsing. First I was trying to just reset the size and maximum size but then I've noticed that I cannot resize the widgets anymore. When I set the minimum size the resizing is possible again but the widget resizes to content and basically ignores the stored size which was before collapsing.
void AnnotationDockWidget::setCollapsed(bool isCollapsed) { if (isCollapsed) { mSizeBeforeCollapse = size(); setFixedSize(0, 0); } else { setFixedSize(mSizeBeforeCollapse); setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); setMinimumSize(0, 0); // Doing this resizes the widget to its content and the mSizeBeforeCollapse is ignored. // Without this line everything has correct size but I cannot resize the widgets. } }
Any idea how to prevent the resize to content or restore resizing capability without setting the minimum size?