Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何设置QWidget宽度?我知道setGeometry(QRect& rect)函数可以做到这一点,但在这种情况下,我应该使用geometry()函数来获取我的以前的参数QWidget,然后我应该增加宽度并使用 setGeometry(..)。有没有直接的方法,比如:
QWidget
setGeometry(QRect& rect)
geometry()
QWidget aa; aa.setWidth(165); //something like this?
resize()可能会更好用。
resize()
示例用法:
widget->resize(165, widget->height());
QWidget 参考。
尝试检查所有可用的“yyysize”方法(因为 Qt 小部件有不同的大小调整策略,您可能需要一些特殊的东西)。
基本上,是的,它是resize(...).
resize(...)
如果之后宽度不会改变,您可以使用setFixedWidth:
setFixedWidth
widget->setFixedWidth(165);
同样,要在不改变宽度的情况下改变高度,有setFixedHeight.
setFixedHeight