Qt: resizing a QLabel, containing a QPixmap, while keeping it's aspect ratio?

In order to change the label size you can select an appropriate size policy for the label like expanding or minimum expanding.

In order to change the label size you can select an appropriate size policy for the label like expanding or minimum expanding. You can scale the pixmap by keeping its aspect ratio every time it changes: QPixmap p; // load pixmap // get label dimensions int w = label->width(); int h = label->height(); // set a scaled pixmap to a w x h window keeping its aspect ratio label->setPixmap(p. Scaled(w,h,Qt::KeepAspectRatio); There are two places where you should add this code: When the pixmap is updated In the resizeEvent of the widget that contains the label.

Hm yes, this was basically the core when I subclassed QLabel. But I thought this use case (showing Images with arbitrary size in Widgets of arbitrary size) would be common enough to have something like it implementable via existing code... – marvin2k Nov 21 at 15:16 AFAIK this functionality is not provided by default. The most elegant way to achieve what you want is to subclass QLabel.

Otherwise you can use the code of my answer in a slot/function which will be called every time the pixmap changes. – webclectic Nov 21 at 15:29 since I want the QLabel to automagically expand based on the users resizing of the QMainWindow and the available space, I can't use the signal/slot solution -- I can't model an expanding policy this way. – marvin2k Nov 21 at 15:53 You have to do in the resizeEvent of the widget where the label is.

– webclectic Nov 21 at 16:34.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions