PDA

View Full Version : Scale an image and assign it to a QPushButton



harmodrew
10th August 2010, 09:15
Hello!

I'd like to set the background image of one QPushButtons, but I'd like a scaled baskground, so the image should adapt to the button dimnsion.
Using SetStyleSheet did'nt work for me. I tried even with che QPixmap::scaled() assigning it to the SetIcon method of the button but the image is shown very little...anyone has any idea?

Thanks

Lykurg
10th August 2010, 10:23
Have you had a look at "QPushButton and images" at the Qt Style Sheets Examples?
Otherwise you have to subclass QPushButton and do the background drawing yourself.

harmodrew
10th August 2010, 11:46
I solved using this code:



QIcon img("/img/ico.bmp");
button.setIcon(img);
button.setIconSize(QSize(button.width(), button.height()));