views:

44

answers:

2

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?

A: 

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.

Darqan
This is what I used. But I have asked for another kind of solution (may be a better one).
Narek
+2  A: 

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.

liaK
Yes, this is what I need!
Narek