I have a QSplitter with one large widget followed by few small ones. When a new widget is added, the small ones are shrunk below their recommended sizeHint()
even though the large one still has much more space than its sizeHint()
.
Can I change this behaviour? Do I need to use QSplitter::setSizes()
to do that and if so, how to detect that some widget was added/removed/resized?
I want the widgets to be freely resizable, so using setFixedHeight()
is not an acceptable solution.
For example, I have two widgets with preferred height 200px (first screenshot). When I add the third one, it takes more than preferred height, shrinking the others even though all could have their preferred height.
CodePudding user response:
Try QSplitter::setStretchFactor(index, factor);
. For example set factor=0 for first widget and factor=1 for rest of the widgets.
You can install event filter and filter for QEvent::LayoutRequest
to detect that some widget was added/removed, although it can be fired for other reasons too.