Narek
Narek

Reputation: 39881

How to set QWidget width?

How to set QWidget width? 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(..). Is there any direct way to that, say:

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

Upvotes: 38

Views: 88787

Answers (4)

JimDaniel
JimDaniel

Reputation: 12703

resize() might be better to use.

Example usage:

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

Upvotes: 68

Donald Duck
Donald Duck

Reputation: 8882

If the width won't change afterwards, you can use setFixedWidth:

widget->setFixedWidth(165);

Similarly, to change the height without changing the width, there is setFixedHeight.

Upvotes: 7

Petrucio
Petrucio

Reputation: 5679

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

Upvotes: 15

M. Williams
M. Williams

Reputation: 4985

QWidget reference.

Try examining all available "yyysize" methods (because there are different sizing policies for Qt widgets and you might need something special).

Basically, yes, it's resize(...).

Upvotes: 6

Related Questions