In my project, I have a Group box with a few elements that may need to be hidden, with other elements above and below. If I hide those elements with setHidden(true), the elements are hidden but that leaves a large space in between the other elements.

How would I be able to compact the group box after hiding those elements, so there isn't such a big space?

有帮助吗?

解决方案

The reason is not in invalidate(). It's because you have an improper layout on you GroupBox content. if you hide() or show() any QWidget QT automatically invalidates everything up to top-most parent which can be affected by visibility change. So in you case QGroupBox is missing layout, so then you hide element there is nothing to change in regards of QGroupBox geometry, that's why you don't see expected stretching.

其他提示

Without code, it's a little bit hard to guess, what is missing.

Have you tried QLayout::invalidate() on the layout that is holding your group box after hiding the box?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top