[SOLVED] How to overlap images with resizing in a broken layout qframe
-
wrote on 2 Oct 2015, 08:13 last edited by xyz0k 10 Jun 2015, 07:14
Hello to everyone,
I am quite new using QT and I am trying to get the following behavior working in QT:
I have been using QT Designer to define the graphical layout making the source code interaction easier. I have 3 QLabels so far overlapped in the same QFrame. Like is shown in the image below:
I am able to achieve overlapping setting each QLabel background transparency in project.ui file like this:
#frameBigPig { background: transparent; } #frameBigPigOutdoor { background: transparent; } #frameBigPigBasic { background: transparent; }
And finally, I set the QT C++ code like that:
ui.frameDog->setPixmap(QString(":/dog.png")); ui.frameDuck->setPixmap(QString(":/duck.png")); ui.frameShark->setPixmap(QString(":/shark.png"));
By doing that, I achieve Image overlapping, but the the Image does not get resized. The current behaviour and the expected one is depicted in the following image:
Thanks for your time,
Best regards.
-
Lifetime Qt Championwrote on 2 Oct 2015, 12:28 last edited by mrjj 10 Feb 2015, 12:32
Hi and welcome
The QLabel will be fit to the image size and not the other way around. (sadly)
If you want to keep the image with in a some box, you must re-size it your self.QPixmap p( QString(":/dog.png") ); int w = label->width(); int h = label->height(); // set a scaled pixmap to a w x h box keeping its aspect ratio label->setPixmap(p.scaled(w,h,Qt::KeepAspectRatio));
Note that you should the the MaximumHeight of the QLabel (with the dog) to the max size you think it should have before
setting the image. (label->setMaximumHeigh( xxx) ) -
Hi and welcome
The QLabel will be fit to the image size and not the other way around. (sadly)
If you want to keep the image with in a some box, you must re-size it your self.QPixmap p( QString(":/dog.png") ); int w = label->width(); int h = label->height(); // set a scaled pixmap to a w x h box keeping its aspect ratio label->setPixmap(p.scaled(w,h,Qt::KeepAspectRatio));
Note that you should the the MaximumHeight of the QLabel (with the dog) to the max size you think it should have before
setting the image. (label->setMaximumHeigh( xxx) )wrote on 5 Oct 2015, 08:26 last edited byHi @mrjj,
Thank you fer helping me. Your solution works, even though as the dog's Image needs to be bigger as there will be some details that needs to be showed clearly.
I tried to increase the available space (reducing the spacing between the horizontal spacers) but the result is still being the same (like if the change does not were done).
Any Idea?
Thank you for your help and time.
Best regards.
-
Lifetime Qt Championwrote on 5 Oct 2015, 08:37 last edited by mrjj 10 May 2015, 08:39
Hi
Well im not 100% sure how you setup the inner box.
if you want frameAnimalConatiner to be bigger, you could set its MinimumWidth or height and
spacers will follow that.Are you planning on animation later on ?
-
wrote on 6 Oct 2015, 07:14 last edited by
Perfect! You are right, I don't know why it wasn't working but it works now.
Thank you so much.
P.D: No, the images are going to be static.
Cheers.
-
Perfect! You are right, I don't know why it wasn't working but it works now.
Thank you so much.
P.D: No, the images are going to be static.
Cheers.
@xyz0k
Super!
well layouts are funky. And smart.Ok. Since you just did not take an image program and made
one new picture with all in it, I assume you
going to use different images overlaid ? -
wrote on 8 Aug 2017, 12:55 last edited by
When a picture file that I bring in from Windows is imported into qt, it breaks. What should I do?
-
When a picture file that I bring in from Windows is imported into qt, it breaks. What should I do?
@sohyun
breaks in what way?
Can you upload the picture to postimage.org and post link here ? -
@sohyun
breaks in what way?
Can you upload the picture to postimage.org and post link here ? -
Hmm. that is odd.
Do you load the same image file on both platforms?
What is the format ? (jpg,png) etc.Can you upload the original image so i can try in my linux box?
Maybe a support SO has issues on your box or something like that. -
Hmm. that is odd.
Do you load the same image file on both platforms?
What is the format ? (jpg,png) etc.Can you upload the original image so i can try in my linux box?
Maybe a support SO has issues on your box or something like that.wrote on 9 Aug 2017, 05:08 last edited byThis post is deleted! -
@sohyun
Hi
I tried in Qt 5.7 on Mint/ubuntu linux and it was shown as
expected. ( not broken)I put the image in res file and showed it on a label.
Do yo use QImage or how do you show it ?
-
@sohyun
Hi
I tried in Qt 5.7 on Mint/ubuntu linux and it was shown as
expected. ( not broken)I put the image in res file and showed it on a label.
Do yo use QImage or how do you show it ?
-
@mrjj oops, I had a mistake. Widget form has a dot. so it seems to have appeared.
if it occurs again, I will ask something someday. :)
thank your helping :)
Have a nice day!oh, so it was not the image that was broken?
super
Nice day to you too