布局:如何使一个小部件的垂直布局的其余部分变成其他小部件的3倍 [英] Layout : How to make one widget 3x the rest in a vertical layout

查看:68
本文介绍了布局:如何使一个小部件的垂直布局的其余部分变成其他小部件的3倍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在垂直布局中有3个表(A,B和C),这3个表的大小策略(水平和垂直)设置为扩展.如何使表A的大小是B和C的3倍,并始终保持该比例.我是通过QT Designer执行此操作的.

I have 3 tables (A,B and C) in a vertical layout.The size policy (Horizontal and vertical) of these 3 are set to expanding. How can I make table-A 3 times the size of B and C and always have that ratio maintained. I am doing this through QT Designer.

更新:

为了测试布局拉伸方法.我将四个QlistWidgets垂直布局内添加到具有水平布局的窗体中.这是表单的XML

In order to test the layout stretch method. I added four QlistWidgets inside a vertical layout to a form having a horizontal layout. Here is the XML for the form

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>formPracticeClass</class>
 <widget class="QMainWindow" name="formPracticeClass">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>847</width>
    <height>661</height>
   </rect>
  </property>
  <property name="sizePolicy">
   <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
    <horstretch>0</horstretch>
    <verstretch>0</verstretch>
   </sizepolicy>
  </property>
  <property name="windowTitle">
   <string>formPractice</string>
  </property>
  <widget class="QWidget" name="centralWidget">
   <layout class="QHBoxLayout" name="horizontalLayout">
    <item>
     <layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,0,0,0">
      <item>
       <widget class="QListWidget" name="listWidget"/>
      </item>
      <item>
       <widget class="QListWidget" name="listWidget_3"/>
      </item>
      <item>
       <widget class="QListWidget" name="listWidget_2"/>
      </item>
      <item>
       <widget class="QListWidget" name="listWidget_4"/>
      </item>
     </layout>
    </item>
   </layout>
  </widget>
 </widget>
 <layoutdefault spacing="6" margin="11"/>
 <resources>
  <include location="formpractice.qrc"/>
 </resources>
 <connections/>
</ui>

具有4个小部件的垂直布局的拉伸布局为1,0,0,0.最上面的窗口小部件的高度看起来比其他窗口小.我希望最上面的小部件要比其他小部件大2倍

The vertical layout with the 4 widgets has a stretch layout of 1,0,0,0. The height of the topmost widget looks smaller to the others. I want the topmost widget to be 2 times bigger than the others

推荐答案

在包含3个表的布局上,在Qt Designer中将layoutStretch属性设置为3,1,1.这指定布局中的第一个元素的空间应为布局中其他两个元素的3倍.

On the layout that contains the 3 tables, set the layoutStretch property to 3,1,1 in Qt Designer. This specifies that the first element in the layout should have 3 times the space as the other two elements in the layout.

更新:

对于更新后的示例.ui文件,通过将layoutStretch设置为2,1,1,1,可以使最上面的小部件的大小比其他小2倍:

For your updated example .ui file, you can make the topmost widget to be 2 times larger than the others by setting the layoutStretch to 2,1,1,1:

     <layout class="QVBoxLayout" name="verticalLayout_2" stretch="2,1,1,1">

请注意,Stretch属性在布局的不同元素之间指定 ratios .换句话说,如果将layoutStretch属性中的元素之一设置为0,则不会获得预期的结果.

Note that the stretch property specifies ratios between the different elements of the layout. In other words, you won't get the desired results if you set one of the elements in the layoutStretch property to 0.

这篇关于布局:如何使一个小部件的垂直布局的其余部分变成其他小部件的3倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆