Qt splitter layout resize behaviour using Qt Designer

20,511

Solution 1

You can play with the "Horizontal Stretch" and "Vertical Stretch" properties to change the position of the split.

For example with both the vertical stretch of the top central QTabWidget and the horizontal stretch of the central QSplitter at 1 and all the other values kept at 0, you'll get the result you want.

When you have multiple non-zero stretch values, the result of the ratio (e.g.: vertical strech at 2 and 1 for the 2 central QTabWidgets => 2/3 and 1/3) is not visible in the designer but seems to be working when you run the application.

PS: You can also achieve the same result with tabbified QDockWidgets but the dock tabbification is not possible through the designer only.

Solution 2

I set start position that:

QList<int> list= ui->splitter->sizes();
list.replace(0,this->height()/0.3);
list.replace(1,this->height()/0.7);
ui->splitter->setSizes(list);

and remember to minimum size child widget

Share:
20,511
Joey Roosing
Author by

Joey Roosing

Updated on July 09, 2022

Comments

  • Joey Roosing
    Joey Roosing almost 2 years

    I have an issue with size in my view made in Qt with drag and drop.

    Let me start with an image to help me explain

    enter image description here

    This is the mainwindow for my form.

    What happens is:

    We have 4 tab widgets. the left tab widget has a horizontal splitter to the 2 mid widgets. The 2 mid widgets have a vertical splitter, and a horizontal splitter on the left and right side.

    The right widget has a vertical splitter on its left hand.

    So all views are connected using splitters.

    Lastly the mainform sticks every thing together in a resizable way using horizontal layout.

    The problem is, the width of the leftmost and rightmost widgets are fixed (in designer). I want them to be smaller in width. Something similar to:

    enter image description here

    You can see the widgets are resized. I was able to do this running the application, and manually adjusting the splitters. Is there a way in QtDesigner to do this? I tried playing with policies. I didn't really get any further however. Does this indicate a lack of knowledge of my part about policies? Perhaps layouts in general?

    What options should I use to achieve the desired layout using QtDesigner. I want to avoid using code.

    Hope I will be able to solve this soon. It must be overlooking something simple..

  • Joey Roosing
    Joey Roosing about 12 years
    I can't believe it was this simple. I wwere right with the first one, mid widget and mid splitter to stretch 1 and it worked.
  • johngreen
    johngreen about 12 years
    Thanks ! Worked like a charm !
  • fateflame
    fateflame almost 5 years
    Just a small not for someone who may not find where to set "Horizontal/Vertical Stretch" in QtDesigner like me, these features are set under "Size Policy", which cannot be reached through search box directly