Make sure the scaledContents property of the label is false.
Make sure the scaledContents property of the label is false.
Hi,
Yes, "scaledContents" is set to false.
The main application have a Horizontal Layout, that contains, on the left the QLabel to show the image and on right a set of widgets that have other layouts.
When the image is shown, the QLabel expands horizontally until the right layout don't let it to grow more.
Thanks,
Òscar Llarch i Galán
Is the expansion caused by the image not fitting into smaller label? You might want to scale it accordingly or use QScrollArea if that's the case.
Hi,
So, the solution is to get the QLabel size and resize the image to fit the QLabel size. Right?
Thanks,
Òscar Llarch i Galán
Yes, that's correct.
Hi,
I'm having a little issue
I want to keep aspect ratio so I set "height" of the scaled image to a big value(bigger that width).Qt Code:
qImage = qImage.scaled(QSize(ui.myLabel->width(),1000),Qt::KeepAspectRatio,Qt::SmoothTransformation);To copy to clipboard, switch view to plain text mode
Every time I show an image, the QLabel gains a little width(maybe 1 pixel).
I don't resize the QLabel height because it is autoresized when show the image(fitting to the image width and height).
Thanks,
Òscar Llarch i Galán
You should always keep a verbatim copy of the image instead of resizing scaled down images. As for the size, you need to fix the size of the label if you rely on it when resizing the image. You needn't pass "1000" as the height - pass the height of the label. The size of the image probably increases because of a margin between the label's border and the pixmap.
Hi,
Oh, so I have to get a copy of the width and height of the image resized when the QLabel is resized(when the application resizes), and resize the image with this values.
Yes, but the application queries on a DB and so the image is reloaded every time.You should always keep a verbatim copy of the image instead of resizing scaled down images
Thanks,
Òscar Llarch i Galán
I try to avoid the constant loading by using a QPixmapCache, but I do not know if it will solve your problem.
Hi,
Thanks, but I don't have this problem.
The problem was the size of the QLabel and the QImage and it has been solved.
The problem is not to load the image every time, because I don't need to speed up this part of code. It queries the name of the image to show on a DB an then load it on the QLabel. That's all.
Òscar Llarch i Galán
Hi,
So, the solution is to get the QLabel size and resize the image to fit the QLabel size. Right?
But, the width of the image will be the width of the QLabel, but the height of the QLabel have to be resized to the new image haight to not get image stretching. The QLabel on a layout let me resize the height?
Thanks,
Òscar Llarch i Galán
Bookmarks