PDA

View Full Version : Qt: How to set the size of Pixmap?



sonulohani
1st June 2012, 10:19
I want to set the size of pixmap. The code is defined below.


QPixmap pix("alarm.png");
painter->drawPixmap(pointf[i], pix);


It is showing a bigger image.
How to set the size?

mvuori
1st June 2012, 14:24
You can either
1) Scale the pixmap befor drawing it, or
2) Use a version of drawPixmap that will do the scaling:

void QPainter::drawPixmap ( const QRectF & target, const QPixmap & pixmap, const QRectF & source )

Draws the rectangular portion source of the given pixmap into the given target in the paint device.

Note: The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.

sonulohani
5th June 2012, 05:37
this one works, the one i am showing below--------->



int x=points->x();
int y=points->y();
painter->drawpixmap(x,y,width,height,pixmap);//here replace the width and height with the pixmap width and height that you want to resize.


And then you will get the image with the size that you've configured.