Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt splitter layout resize behaviour using Qt Designer

Tags:

c++

layout

qt

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

like image 569
Joey Roosing Avatar asked Mar 10 '12 20:03

Joey Roosing


2 Answers

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.

like image 192
alexisdm Avatar answered Sep 28 '22 11:09

alexisdm


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

like image 25
Adam111p Avatar answered Sep 28 '22 10:09

Adam111p