Preventing widget with layout from expanding in QSplitter
-
I have a complex widget and layout that sits in a QSplitter, and want the QSplitter to keep the widget at a fixed size unless collapsed, while allowing the other widgets the expand at will. The form is created in QtCreator.
See screenshot:
Thanks!
-
Hi Patrick,
there are at least two solutions for this:
-
Take the top widget out of the splitter and tell it to have the "Fixed" sizePolicy.
-
Tell the splitter to use only the lower widgets for scaling. There is no GUI setting for this, so you need to do it in source (e.g. in constructor). It would look like:
@
// The stretchFactor has a default of 0,
// so leave index 0 at default
ui->vSplitter->setStretchFactor(1,1);
ui->vSplitter->setStretchFactor(2,1);
@
With the second solution, the user will be able to resize the height of the top widget manually by dragging the splitter below it. The first solution prevents it.
Greets
Jazzco -
-
Nuts. So it sounds like I am already achieving #2, and for #1 I need to run the UIC code to build the form and then remove and then re-insert the first widget in the splitter?