简体   繁体   English

QT Designer - 如何创建布局

[英]QT Designer - How to create a layout

I'm new to QT, especially QT Designer and I found it to be quite unintuitive.我是 QT 的新手,尤其是 QT Designer,我发现它非常不直观。

I have the following layout which I'm trying to achieve in Qt Designer.我有以下布局,我试图在 Qt Designer 中实现。

在此处输入图像描述

Explication:解释:

  • YELLOW -> the application window黄色 -> 申请 window
  • BLUE -> 2 side buttons with the heigh of red heigh and white heigh蓝色 -> 2 个侧面按钮,红色高度和白色高度
  • RED -> should be around of 2/3 of the blue heigh红色 -> 应该是蓝色高度的 2/3 左右
  • WHITE -> should also be around 1/3 of blue heigh白色 -> 也应该是蓝色高度的 1/3 左右

Layouts:布局:

  • REDs -> Lay Out Horizontally红色 -> 水平布局
  • WHITEs -> Lay Out Horizontally白色 -> 水平布局
  • REDs + WHITEs -> Lay Out Vertically红色 + 白色 -> 垂直布局
  • BLUE + (REDs + WHITEs) -> Lay Out Horizontally蓝色 + (红色 + 白色) -> 水平布局
  • (BLUE + (REDs + WHITEs)) + SPACER -> Lay Out Vertically (because it's needs to be some space between the buttons and the top of application) (BLUE + (REDs + WHITEs)) + SPACER -> Lay Out Vertically (因为它需要在按钮和应用程序顶部之间有一些空间)

BUT if I will apply of those which I said above, I'm going to get something like this:但是如果我将应用我上面所说的那些,我将得到这样的东西:

在此处输入图像描述

So far as I've search I can use the Lay Out Horizontally in Splitter and Lay Out Horizontally Vertically in Splitter to keep the aspect ratio that I want, but then I can split the app and I don't want that.就我的搜索而言,我可以使用拆分器中的水平布局和拆分器中的垂直垂直布局来保持我想要的纵横比,但我可以拆分应用程序,但我不想要那样。 Can anyone help me to understand how can I do this?谁能帮助我了解我该怎么做? Or the only way of doing this would be from C++?或者这样做的唯一方法是来自 C++?

I think what you are looking for is QGridLayout .我认为您正在寻找的是QGridLayout

In a QGridLayout you can decide for each widget how many rows it will occupy (just drag its borders) and the various "weigths" (parameter is called rowStretch or columnStretch ) of each row/column.在 QGridLayout 中,您可以为每个小部件决定它将占用多少行(只需拖动其边框)以及每行/列的各种“weigths”(参数称为rowStretchcolumnStretch )。

Example:例子: 使用 QGridLayout 的布局 Your layout may be composed as follows:您的布局可能组成如下:

A big yellow rectangle is the first QGridLayout (1 row x 5 columns), wich contains (left to right):一个黄色的大矩形是第一个 QGridLayout(1 行 x 5 列),其中包含(从左到右):

  • Your first Blue element (occupies 1 row and 1 column);您的第一个蓝色元素(占据 1 行和 1 列);
  • 3 QGridLayouts in green; 3 个 QGridLayouts 为绿色;
  • Your second Blue element (occupies 1 row and 1 column);您的第二个蓝色元素(占用 1 行和 1 列);

The green QGridLayouts (2 rows x 2 columns) are configured this way:绿色的 QGridLayouts(2 行 x 2 列)是这样配置的:

  • Your red element (occupies 1 row and 2 columns, and has a rowStretch of 2);你的红色元素(占1行2列,rowStretch为2);
  • Your first white element, (occupies 1 row and 1 column, and has a rowStretch of 1);你的第一个白色元素,(占1行1列,rowStretch为1);
  • Your second white element, (occupies 1 row and 1 column, and has a rowStretch of 1);你的第二个白色元素,(占1行1列,rowStretch为1);

This way red and white elements are proportioned 2 to 1 vertically and (since togheter they occupy the same row of the blue ones) the blue height is the sum of red + white.这样,红色和白色元素在垂直方向上的比例为 2 比 1,并且(因为它们一起占据了蓝色元素的同一行)蓝色高度是红色 + 白色的总和。

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

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