How to make a resizable image
-
Hello, I added a QPixmap to a QLabel. But it must be set at a fixed size. Is there a way to resize it according to the size of the QLabel? I mean when I expand or shrink the QLabel with my mouse, I want that image resized simultaneously.
-
Hi,
Sounds like you are looking for the QLabel:: scaledContents property.
-
Hi,
Sounds like you are looking for the QLabel:: scaledContents property.
@SGaist said in How to make a resizable image:
Hi,
Sounds like you are looking for the QLabel:: scaledContents property.
No this is not what I want.
Actually during my test, setScaledContents(true) only fits the image to the size of the label. When I magnify the label, the image doesn't change together with it.
-
@MasterBlade said in How to make a resizable image:
magnify the label,
What do you do when you magnify it ?
QLabel:: scaledContents scales the image to the size of Labels rect.
If you mean that the QLabel do not follow dialog, its because you must
add a layout to the dialog and then label into layout to have it follow the Dialog window.That is, place Label on dialog form.
Right click and select layout (on free spot on form, not label) ,
select say layout horizontally
Now it follows the Dialog. -
@MasterBlade said in How to make a resizable image:
magnify the label,
What do you do when you magnify it ?
QLabel:: scaledContents scales the image to the size of Labels rect.
If you mean that the QLabel do not follow dialog, its because you must
add a layout to the dialog and then label into layout to have it follow the Dialog window.That is, place Label on dialog form.
Right click and select layout (on free spot on form, not label) ,
select say layout horizontally
Now it follows the Dialog.@mrjj said in How to make a resizable image:
@MasterBlade said in How to make a resizable image:
magnify the label,
What do you do when you magnify it ?
QLabel:: scaledContents scales the image to the size of Labels rect.
If you mean that the QLabel do not follow dialog, its because you must
add a layout to the dialog and then label into layout to have it follow the Dialog window.That is, place Label on dialog form.
Right click and select layout (on free spot on form, not label) ,
select say layout horizontally
Now it follows the Dialog.Wow, this did work! Many thanks!
So the next problem is that the image doesn't maintain its aspect ratio when resizing. Is there a way to keep its aspect ratio?
-
- Is there a way to keep its aspect ratio?
The most/one of the common solution is to subclass QLabel and
use pixmap.scaled(w,h,Qt::KeepAspectRatio) and draw it by hand.You can grab AspectRatioPixmapLabel class from here
-
- Is there a way to keep its aspect ratio?
The most/one of the common solution is to subclass QLabel and
use pixmap.scaled(w,h,Qt::KeepAspectRatio) and draw it by hand.You can grab AspectRatioPixmapLabel class from here
@mrjj said in How to make a resizable image:
- Is there a way to keep its aspect ratio?
The most/one of the common solution is to subclass QLabel and
use pixmap.scaled(w,h,Qt::KeepAspectRatio) and draw it by hand.You can grab AspectRatioPixmapLabel class from here
Sorry I didn't go to this forum recently. This did work. Many thanks!!
Allow me for one more stupid question. The image keeps it AR, but the window doesn't. Is there a way to make the window also keep its AR?
I tried similar ways but it doesn't seem to be working.