QLabel with image stretched out
-
Been designing a window for bactria analysis and one of the main functions I want to add is the option to upload an image with the help of QT Designer. However, when I maximize the window, the image looks too stretched out. Anyway to fix this? Here's what it looks like:
The image is shown through QLabel. Here are the objects for additional detail:
-
-
@Christian-Ehrlicher I disabled it (as it was enabled before) but I'm still getting the same issue unfortunately:
-
If you disable scaled contents then your image will not be scaled. And your picture shows that now the pixmap is no longer scaled to the width/height of your label.
-
I am assuming you were expecting that the image would be pillar-boxed i.e. scaled to the height of the client area, without changing aspect ratio, and placed in the centre.
One way to achieve this is to keep a copy of the original QPixmap and scale it as needed in the relevant QWidget::resizeEvent(). You can see the logic in the Screenshot Example
void Screenshot::resizeEvent(QResizeEvent * /* event */) { QSize scaledSize = originalPixmap.size(); scaledSize.scale(screenshotLabel->size(), Qt::KeepAspectRatio); if (scaledSize != screenshotLabel->pixmap().size()) updateScreenshotLabel(); }
-
@Christian-Ehrlicher I see. Is there anyway to have the image remain in normal size even when the window is maximized? Should I include the Qlabel inside a widget for it to work?
-
What is 'normal size'? If you want to make sure that all is drawn without stretching then use @ChrisW67 's solution.
-
@Rangerguy128
As @Christian-Ehrlicher says we don't know what "normal" size means to you. If you mean you have an original image file with a certain size picture in it and you don't want the user to resize it bigger than this you could set the maximum size to the original size. You were asking about resizing originally, now you don't want it to resize, resizing when small but not too large, what precisely do you want or not want?