简体   繁体   English

如何设置QWidget宽度?

[英]How to set QWidget width?

How to set QWidget width? 如何设置QWidget宽度? I know setGeometry(QRect& rect) function to do that, but in that case I should use geometry() function to get former parameters of my QWidget , then I should increment the width and use setGeometry(..). 我知道setGeometry(QRect& rect)函数可以做到这一点,但在这种情况下,我应该使用geometry()函数来获取我的QWidget前参数,然后我应该增加宽度并使用setGeometry(..)。 Is there any direct way to that, say: 有没有直接的方法,说:

QWidget aa;
aa.setWidth(165); //something like this?

resize() might be better to use. resize()可能更好用。

Example usage: 用法示例:

widget->resize(165, widget->height());
widget->resize(165, widget->height());

QWidget reference. QWidget参考。

Try examining all available "yyysize" methods (because there are different sizing policies for Qt widgets and you might need something special). 尝试检查所有可用的“yyysize”方法(因为Qt小部件有不同的大小调整策略,您可能需要一些特殊的东西)。

Basically, yes, it's resize(...) . 基本上,是的,它是resize(...)

If the width won't change afterwards, you can use setFixedWidth : 如果之后宽度不会改变,可以使用setFixedWidth

widget->setFixedWidth(165);

Similarly, to change the height without changing the width, there is setFixedHeight . 同样,要在不改变宽度的情况下更改高度,请使用setFixedHeight

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

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