简体   繁体   English

Qt拆分器布局使用Qt Designer调整行为大小

[英]Qt splitter layout resize behaviour using Qt Designer

I have an issue with size in my view made in Qt with drag and drop. 我在Qt中使用拖放操作查看了大小问题。

Let me start with an image to help me explain 让我先从图像开始帮我解释一下

在此输入图像描述

This is the mainwindow for my form. 这是我表单的主窗口。

What happens is: 会发生什么:

We have 4 tab widgets. 我们有4个标签小部件。 the left tab widget has a horizontal splitter to the 2 mid widgets. 左标签小部件有一个水平分割器到2个中间小部件。 The 2 mid widgets have a vertical splitter, and a horizontal splitter on the left and right side. 2个中间小部件有一个垂直分离器,左侧和右侧有一个水平分离器。

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: 类似的东西:

在此输入图像描述

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? 在QtDesigner中有没有办法做到这一点? 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. 我应该使用什么选项来使用QtDesigner实现所需的布局。 I want to avoid using code. 我想避免使用代码。

Hope I will be able to solve this soon. 希望我能尽快解决这个问题。 It must be overlooking something simple.. 它必须忽略一些简单的东西..

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. 例如,顶部中央QTabWidget的垂直拉伸和中央QTabWidget的水平拉伸QSplitter 1,所有其他值保持为0,您将获得所需的结果。

When you have multiple non-zero stretch values, the result of the ratio (eg: vertical strech at 2 and 1 for the 2 central QTabWidget s => 2/3 and 1/3) is not visible in the designer but seems to be working when you run the application. 当你有多个非零拉伸值时,比率的结果(例如:2个中心QTabWidget的垂直拉伸和1 => 2/3和1/3)在设计师QTabWidget不到,但似乎是运行应用程序时工作。

PS: You can also achieve the same result with tabbified QDockWidget s but the dock tabbification is not possible through the designer only. PS:您也可以使用标签化的QDockWidget获得相同的结果,但只能通过设计器实现停靠标签化。

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 并记住最小尺寸的儿童小部件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM