PDA

View Full Version : Pixmap scaling



yellowmat
4th January 2007, 15:19
Hi everybody,

I want to display an image (.png) over a QPushButton object in order to customize its look.

My png file has a size bigger than my button's so what I am trying to do is scaling down my image size to the button's size and then display the image over my button.

The problem is that my pixmap is never scalled to the button's size and I don't understand why, so if somebody could help me it would be great.

Here is my code :


QPushButton but;

QImage img;
img.resize(90, 24);
img.load("play.png");
img.scale(90, 24);

QPixmap pix;
pix.convertFromImage(img);

but.setPixmap(pix);


Thanks in advance

LarryDobson
4th January 2007, 15:41
Greetings,
In your code, you had:

img.scale( 90, 24 );

surely, you meant
img.scaled( 90, 24 );

the shorthand of your code would look like this:

QPushButton but;
QPixmap pixmap( "Play.png" );
but.setPixmap( pixmap.scaled(90,24) );

It is not necessary to start out as a QImage.

Larry

yellowmat
4th January 2007, 15:53
I'm sorry but there is no function named "scaled" in Qt3 that I can call from WImage, neither QPixmap so your solution does not work for me :o

LarryDobson
4th January 2007, 16:01
Oops. My bad. Didn't notice the Qt3 qualifier.