How to resize the QIcon inside QPushButton dynamically?
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.
Re: How to resize the QIcon inside QPushButton dynamically?
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.
Re: How to resize the QIcon inside QPushButton dynamically?
Quote:
Originally Posted by
high_flyer
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 ....
Code:
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 ...