开发者

Qt - How to specify and make constant an element size in a layout?

Say there is a QHBoxLayout and so开发者_如何学Cme widgets in it. How to specify a widget width and hight in the layout, so that while resizing the widget which containes the layout the given width and hight stay constant?


You can use

void QWidget::setFixedSize ( int w, int h )

which Sets the width of the widget to w and the height to h. This will make the size of the particular widget fixed when the window is re-sized.

Also you can use the combination of these functions,

void QWidget::setFixedHeight ( int h )

and also

void QWidget::setFixedWidth ( int w )

whichever is required for your need.. Hope it helps.


One (simple) way to do this is to use QWidget::setMinimumSize and QWidget::setMaximumSize functions to set minimum size and maximum size to be the same. Doing this will prevent widget from expanding and shrinking. E.g.

widget->setMinimumSize( 200, 100 );
widget->setMaximumSize( 200, 100 );

Of course you can set these values in QtDesigner also.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜