Scaling QPixmap
-
Hello everyone.
First of all thanks a lot for helping me and reading this post.I have a jpeg image as a QPixmap in a scene.
I would like that the QPixmap has a specific size.I try this:
img_scene.scaledToHeight(my_height); img_scene.scaledToWidth(my_width); //img_scene.scaled(my_height,my_width); scene->addPixmap(img_scene);
but it works in the same way than if I do not write scaled...
Any idea to do that?thanks a lot.
-
@AlvaroS
Hello,
You're not actually changing the pixmap. Look at the documentation of QPixmap::scaledToHeight. Try something like this:img_scene = img_scene.scaledToHeight(my_height); img_scene = img_scene.scaledToWidth(my_width);
Kind regards.
-
@mrjj said:
@AlvaroS said:
Hi
Its a classic.
Scaled returns a copy ! it do not change the original.img_scene = img_scene.scaled(my_height,my_width);
will do it.
@kshegunov said:
@AlvaroS
Hello,
You're not actually changing the pixmap. Look at the documentation of QPixmap::scaledToHeight. Try something like this:img_scene = img_scene.scaledToHeight(my_height); img_scene = img_scene.scaledToWidth(my_width);
Kind regards.
Thanks a lot for answering me.
Now it works but not fine.I have some items in my scene and I would like that items appear in foreground so over the QPixmap.
How can I do that?
Thanks again!! -
-
@mrjj Thanks a lot my friend!! It works!!!
Now I have another problem... sorry for being boring.
The image that I add is a irregular square, something like: http://www.maspa.se/SPANSKA/Matematica4/Geometria/Poligonos/Figuras/cuadrilatero1.gif
But in the scene if I write:
img_scene = img_scene.scaledToHeight(my_height);
img_scene = img_scene.scaledToWidth(my_width);The image appears like a perfect regular square like: http://science-all.com/images/square/square-03.jpg
However if I do not write the scaled it appears fine....
Any ideas what am I doing wrong?!
Thanks a lot
-
ehh
Im not sure how scaling the
polygon image could ever make it a rect !?!? -
@mrjj Yes, it seems what I said yesterday, it does not scale the whole image...
Maybe I have to use a Qt::Transformation or something like that...
The other idea that I have watched on the internet is to use Qlabel, but I need to use Scene because I have items there... -
@mrjj said:
@AlvaroS
Hmm i was think we only saw some of it ?
so it looked like rect. :)@AlvaroS said:
@mrjj Yes, it seems what I said yesterday, it does not scale the whole image...
Maybe I have to use a Qt::Transformation or something like that...
The other idea that I have watched on the internet is to use Qlabel, but I need to use Scene because I have items there...I have tried this:
img_scene=img_scene.scaled(my_height,my_width, Qt::IgnoreAspectRatio, Qt::FastTransformation); label_img->setPixmap(img_scene); label_img->setScaledContents(true); scene->addWidget(label_img)
But it works in the same way..