PDA

View Full Version : SetIcon ON for pushbutton does not work



tonnot
14th September 2011, 11:13
I have fed the icons for a button on designer. (Normal on and off) with two different icons.


buton0->setIcon(buton0->icon().pixmap(24,QIcon::Normal,QIcon::On));

Does nothing.....
Any idea ?

high_flyer
14th September 2011, 11:17
See the documentation.
In normal state there is no difference between on and off.
You have to change the state to disabled or selected.

tonnot
14th September 2011, 12:30
mmm.
So I think that the best aproach to change the icon for a button are going to be use another icon of a label (If I'd want to have pre-loaded icons from designer) , ins't it ?
I have a Button with 'edit' icon, If the user click's on it I want to change it to 'save' icon.
What do you think ?
( Or maybe can I set use the selected option? -It is for items on trees . isn't it? )
Thanks

high_flyer
14th September 2011, 12:34
I don't quite understand.
QIcon::pixmap() can generate a new state dependent variant of the pixmap, based on the state.
It will be the same image, but grayed out.
If you want a totally different image, then you will have to supply it of course!

tonnot
14th September 2011, 13:06
Finally.
I want to change the icon of a button depend on some action.
I can't use the icons normal, selected, etc on/off because they are used by the application (mouse move, select an item, etc ).
The only that works for me is the disable icon. (the automatic grey state).

So, finally if I want to change the 'normal' icon I need to set a new Icon (for example from another widget ).
But in this last case, all the icons of the button are changed by the new icon .
So, I have to reload an icon for the disable state.

Of course, all of this can be avoided if I load the icons by its resource - name. ( and use the QIcon:: apropiate values ).
Also If I use another pushbutton with the right icons , all the icons are changed.

Am I right ?
Thanks

wysota
14th September 2011, 13:16
Do you want to change the icon of the button or do you want to change functionality of the button? If the latter, then have two different buttons, hide one and show the other.

tonnot
14th September 2011, 13:24
I have discover that this is the best option (have two different buttons ) , because it is impossible to set the 'grey' disable icon in case of you want a different icon for normal and disabled.
When you set the normal icon, designer automatically converts it to grey and set the disabled icon. If you want a different 'grey' icon and try to set it , designer choose the new 'clean' (not greyed) icon.
So, I'm going to work with two buttons.
Thanks.