1
votes

Say there is a QHBoxLayout and some 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?

2

2 Answers

4
votes

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.

-1
votes

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.