To set icon size to the button size in Qt-S60
Dear All,
I am trying to display the images on the buttons.
I am able to display it.........But what I want is irrespective of the size(That is,less or of greater size than button parameters.)of the image, picture should fit exactly into the button size.
Images gets displayed upon buttons if greater or less than the button size but it won't get fit into the button parameters.
I have set the icon size to the button size using mainImage->setIconSize(QSize(100,160)); API.
But its not taking any effect.....
Need help on this.....
Below is the code I am using..
mainImage = new QPushButton(this);
mainImage->move(25,210);
mainImage->setIconSize(QSize(100,160));
mainImage->setGeometry(70,10,100,160);
mainImage->setFocusPolicy(Qt::TabFocus);
mainImage->show();
QString Imagename(*it5);
NextImagepath = "c:\\Data\\Images\\Pictures\\"+Imagename;
QPixmap imagedisplay(NextImagepath);
QIcon icon(imagedisplay);
mainImage->setIcon(icon);
I am using .jpg image of size 41KB.
Note:
I am using Qt-S60 temple release.
Thanks,
Prajna
Re: To set icon size to the button size in Qt-S60
Hi prajna123,
What pixel size image you are using for the displaying on the button?
You can try resizeing your pixmap.
Use the code
[CODE]
imagedisplay.scaledToHeight(88);
imagedisplay.scaledToWidth(88);
[/CODE]
Hope this will helps you.
Regards
Re: To set icon size to the button size in Qt-S60
Also check if QPixmap::scaled() will help.
Re: To set icon size to the button size in Qt-S60
I am using image of pixel size 270 * 216
May be we have to maintain the aspect ratio
Tried using
imagedisplay.scaledToHeight(88);
imagedisplay.scaledToWidth(88); but it is not taking any effect :(
Need help on this
Re: To set icon size to the button size in Qt-S60
[QUOTE=prajna123;586701]I am using image of pixel size 270 * 216
May be we have to maintain the aspect ratio
Tried using
imagedisplay.scaledToHeight(88);
imagedisplay.scaledToWidth(88); but it is not taking any effect :(
Need help on this[/QUOTE]
Hi,
Your image size is changed or remain as it is?
Re: To set icon size to the button size in Qt-S60
Hi,
One more thing, its not necessary to maintain the aspect ratio also. Its working for my case. You have to maintain the same size of the button and image....
Re: To set icon size to the button size in Qt-S60
[QUOTE=prajna123;586701]
imagedisplay.scaledToHeight(88);
imagedisplay.scaledToWidth(88); [/QUOTE]
Remember: QPixmap::scaledToHeight(),QPixmap::scaledToWidth(),and QPixmap::scaled() method will not scale your exising QPixmap. It will return a new QPixmap with scaled value.
So you can try something like.
[CODE]QPixmap imagedisplay(NextImagepath);
QPixmap scaledImage(imagedisplay.scaled(QSize(88,88)));
QIcon icon(scaledImage);[/CODE]
Or
[CODE]QPixmap imagedisplay(NextImagepath);
QIcon icon(imagedisplay.scaled(QSize(88,88)));[/CODE]
Hope this might help you. :)
Re: To set icon size to the button size in Qt-S60
Thanks a lot.
Below code worked for me. :)
QPixmap imagedisplay(NextImagepath);
QIcon icon(imagedisplay.scaled(QSize(88,88)));
Re: To set icon size to the button size in Qt-S60
Also i am Damn sure that first method (suggested in my previous post) will also work.
Re: To set icon size to the button size in Qt-S60
sssssss I checked that also.
It worked.
Thank you :)
Re: To set icon size to the button size in Qt-S60
Dear All,
I want to share another idea.
I am using resource files for loading icons. I am trying to resize using the standard setIconSize() method. My problem was the icons were not getting larger, although I was able to shrink them.
To solve this, I had to open the images in another external image editor, increase the size and then load once again in the resource.
Look obvious right :)