gpt4 book ai didi

c++ - QGridLayout : change height of a row

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:34:50 25 4
gpt4 key购买 nike

我是 qt 的新手,现在我的窗口看起来像这样:

*---------* *---------* *---------* *---------* 
|ListView1| |ListView2| |ListView3| |ListView4|
| | | | | | | |
*---------* *---------* *---------* *---------*
*---------------------------------------------*
| |
| ListView5 |
| |
*---------------------------------------------*
*---------------------------------------------*
| GridLayout2 |
| |
*---------------------------------------------*

问题是第二行(ListView5)高于第一行和第三行,而我希望第一行高于第三行,第三行应该高于第二行。有办法吗?或者我应该使用 gridlayout 的其他东西吗?谢谢。

最佳答案

我建议您阅读文档 here ,有关将小部件添加到布局时如何分配其大小的信息:

  1. All the widgets will initially be allocated an amount of space in accordance with their QWidget::sizePolicy() and QWidget::sizeHint().
  2. If any of the widgets have stretch factors set, with a value greater than zero, then they are allocated space in proportion to their stretch factor.
  3. If any of the widgets have stretch factors set to zero they will only get more space if no other widgets want the space. Of these, space is allocated to widgets with an Expanding size policy first.
  4. Any widgets that are allocated less space than their minimum size (or minimum size hint if no minimum size is specified) are allocated this minimum size they require. (Widgets don't have to have a minimum size or minimum size hint in which case the stretch factor is their determining factor.)
  5. Any widgets that are allocated more space than their maximum size are allocated the maximum size space they require. (Widgets do not have to have a maximum size in which case the stretch factor is their determining factor.)

假设您没有更改QListViewsizePolicy,那么,它们都具有 的默认sizePolicy展开。这意味着,您只需要设置合适的 stretch factors对于 QGridLayout 中的行。

如果您使用的是 Qt 设计器,只需单击 QGridLayout(或具有 QGridLayout 的小部件),然后在属性编辑器中设置 layoutRowStretch 到类似 3,1,2 的内容。

Property Editor screenshot

3,1,2 将设置第三行填满第二行空白高度的两倍,而第一行将填满空白高度的三倍由第二排拍摄。

如果你想在没有设计器的情况下这样做,你可以使用 setRowStretch ,像这样:

gridLayout.setRowStretch(0, 3);
gridLayout.setRowStretch(1, 1);
gridLayout.setRowStretch(2, 2);

关于c++ - QGridLayout : change height of a row,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39806482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com