Resizing QPixMap to fit QLabel issue
So I have been trying to do this multiple ways,
So far I have
Now the above does scale the image so that it fits, however the problem is that the image looks all compressed and ugly. Is there maybe some better format other than QPixmap, or some way to fix the image so it looks good?
If you know the size of the label on beforehand, and if it is fixed, then you could simply use:
label->setPixmap(pixmap.scaled(myWidth, myHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation));
In any case, drop the
If your label size varies dynamically, e.g. as part of a layout when resizing the window, then you must subclass
QLabelto implement the
resizeEventhandler, as done here:
instead of this, scale the pixmap to labels width and height
@Diracsbracket The label size does vary dynamically. I set a scaled pixmap like you wrote and also included the same line in my event filter ( on resize event ) for my class but it didn't scale properly. I know for a fact that my label's height should have changed but the height of the pixmap didn't. However if I implement the same line with
Then it produces the same result I observed with just :
And like I said, it's scaled, but looks ugly as it is way too compressed horizontally.
I'm thinking maybe this has something to do with the original size format of my pixmap and maybe it just won't scale the way I want it to unless I recreate it with a better size in mind - although not sure how that would work.
I'm thinking maybe this has something to do with the original size format of my pixmap
What is the unscaled pixel size of your pixmap?
Can you post a minimal runnable code version of how you are currently doing things?