Qt QHBoxLayout百分比大小 [英] Qt QHBoxLayout percentage size

查看:754
本文介绍了Qt QHBoxLayout百分比大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在两个QHBoxLayouts之间保持长宽比?

How can I maintain an aspect ratio between two QHBoxLayouts?

例如,我希望QHBoxLayout占整个窗口宽度的三分之一,而另一个则为两个整个窗口宽度的三分之二:

For instance I want a QHBoxLayout to be one third of the entire window width and the other to be two thirds of the entire window width:

如何实现?我尝试弄乱它们中控件的大小提示,但没有成功

How can I achieve this? I tried messing with the size hints of the controls in them but that didn't work out

推荐答案

void QSizePolicy :: setHorizo​​ntalStretch(uchar StretchFactor)

示例:

QHBoxLayout* layout = new QHBoxLayout(form);

QWidget* left = new QWidget(form);
QSizePolicy spLeft(QSizePolicy::Preferred, QSizePolicy::Preferred);
spLeft.setHorizontalStretch(1);
left->setSizePolicy(spLeft);
layout->addWidget(left);

QWidget* right = new QWidget(form);
QSizePolicy spRight(QSizePolicy::Preferred, QSizePolicy::Preferred);
spRight.setHorizontalStretch(2);
right->setSizePolicy(spRight);
layout->addWidget(right);

这篇关于Qt QHBoxLayout百分比大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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