PDA

View Full Version : Problem with setting a label's maximum size



Midleiro F.
20th October 2012, 23:35
Hello!

I'm using a QLabel with a specified QPixmap to show an image in my main window. Whenever I resize the window, I would like that the label stays centered, both horizontally and vertically, but the label's contents (the image) not to be resized. For that I am using both Horizontal and Vertical size policies as Fixed, ScaledContents as false, as MaximumSize as 16777215 x 16777215. This has been working as expected.

What I would like now ito specify a maximum image size so that if the image loaded is larger than the maximum size, have them scaled to fit this maximum. For that, I tried setting MaximumSize as 500x500, and keep the rest as it is (SizePolicy as (Fixed, Fixed)).

What happens now, however, is that the label is being stretched both vertically and horizontally when I resize the window, even though it's SizePolicy is Fixed on both directions, and the new MaximumSize is even smaller than the previous one.

This doesn't seem to make any sense to me. What am I doing wrong?
Thanks!

Ashkan_s
21st October 2012, 10:04
I don't know what is wrong but as a workaround you can try to scale down the pixmap. QPixmap::scaled

boudie
21st October 2012, 18:09
You should use layouts.