Results 1 to 7 of 7

Thread: SetIcon ON for pushbutton does not work

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default SetIcon ON for pushbutton does not work

    I have fed the icons for a button on designer. (Normal on and off) with two different icons.

    Qt Code:
    1. buton0->setIcon(buton0->icon().pixmap(24,QIcon::Normal,QIcon::On));
    To copy to clipboard, switch view to plain text mode 

    Does nothing.....
    Any idea ?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: SetIcon ON for pushbutton does not work

    See the documentation.
    In normal state there is no difference between on and off.
    You have to change the state to disabled or selected.
    Last edited by high_flyer; 14th September 2011 at 10:22.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SetIcon ON for pushbutton does not work

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: SetIcon ON for pushbutton does not work

    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!
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SetIcon ON for pushbutton does not work

    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
    Last edited by tonnot; 14th September 2011 at 12:14.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SetIcon ON for pushbutton does not work

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SetIcon ON for pushbutton does not work

    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.

Similar Threads

  1. Replies: 3
    Last Post: 24th July 2011, 22:13
  2. Replies: 3
    Last Post: 29th April 2011, 08:54
  3. QAbstractButton::setIcon | Icon posiition
    By ouekah in forum Newbie
    Replies: 2
    Last Post: 10th May 2010, 23:56
  4. QTreeWidget Crashing while setText,setFont,setIcon
    By santosh.kumar in forum Qt Programming
    Replies: 3
    Last Post: 19th February 2008, 11:36
  5. setIcon() - different QIcon states?
    By AaronMK in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2008, 03:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.