15
votes

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..

2
I'm using a splitter for the first time, and I don't see ANYTHING in the Designer that allows me to configure the position of the splitter. I was going to attempt to set it via code in the constructor of the dialog (probably try to re-size the component on one side of the splitter to its minimum), but have not gotten there yet. I'd be interested to hear what others have to say.aldo
Glad to ehar im not the only one with this issue. It should be so simple. But setting size constraints like min-width etc do not seem to help for me.Joey Roosing
Sizes can be set using QSplitter's setStretchFactor function. But as you have already noticed, it cannot be set in Qt Designer.user362638
Stretch factor can be set in Qt Designer it falls under SizePolicy, horizontal stretch/vertical stretch. Or is that different from the method u are talking about?Joey Roosing
Horizontal and Vertical Stretch under sizePolicy might be closely connected to the setStrechFactor function, but I can't get the same results by modifying Horizontal and Vertical Stretch values as compared to the setStrechFactor function.user362638

2 Answers

11
votes

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.

1
votes

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