PDA

View Full Version : How to resize the QIcon inside QPushButton dynamically?



gboelter
18th February 2010, 07:58
I have designed a keypad using QPushButton with Icons.

For the keypad I have used QGridLayout, so the user can resize the keypad.

Resizing works fine for the Buttons, but how can I resize the icon too?

With seticon() I can change the icon and with setIconSize() I can change the size of the icon. But according to the manual - if I am right - I can set the size only as a fixed maximum size.

Is there any other way to stretch the icon dynamically together with the Button?

Thanks in advance.

high_flyer
18th February 2010, 08:57
I guess the way to go would be:
1. Scale the icons image file to the maximal size it will need. (with a graphical editing application)
2. call setIconSize() every time you change the size of the botton.

gboelter
18th February 2010, 12:34
I guess the way to go would be:
1. Scale the icons image file to the maximal size it will need. (with a graphical editing application)
2. call setIconSize() every time you change the size of the botton.

Thanks! Because I don't have a better idea too, I will do it in this way now ....



if ( event->type() == QEvent::Resize )
{
for ( int n = 0; n < pushButtonList.size(); ++n )
{
pushButtonList.at(n)->setIconSize( QSize( pushButtonList.at(n)->size().width()-4, pushButtonList.at(n)->size().height()-6 ));
}
....

Thanks agai for giving me this idea ...