QIcon; how to change the state and mode?



  • I was creating many icons and adding QIcon to the tool button,

    @
    QIcon icon;
    icon.addFile(":/IconNormal.png", QSize(), QIcon::Normal, QIcon::On);
    icon.addFile(":/IconActive.png", QSize(), QIcon::Active, QIcon::On);
    icon.addFile(":/IconSelected.png", QSize(), QIcon::Selected, QIcon::On);
    icon.addFile(":/IconDisabled.png", QSize(), QIcon::Disabled, QIcon::On);
    @

    Now if i want to change the state of the button , how should i achieve that, there is no method to change the state of the button.

    [EDIT: code formatting, please wrap in @-tags, Volker]


  • Moderators



  • I have seen that example but Its just not striking me as to how to get the disabled state or selected state as an icon, All i see is the normal state always,. what if I want to modify the the way the selected icon looks,. (I guess QIconEngine class needs to be involved, but still). I am simpoly not able to get the Icons example and its pretty strange the when you select the disabled from the drop down box the disabled become active. now what does it mean



  • What do you mean with "there is no method to change the state of the button"? Of course there is! Check out the enabled and checked properties. Furthermore, can can control if the button has focus or not. A button cannot be selected, so that state is useless for buttons. It is useful for icons in an item view or something like that though.



  • For the tool button you must use "On" and "Off" states to show checked propertie, here is an example:

    @
    toolButton = new QToolButton;
    toolButton->setCheckable(true);
    QIcon qIcon;
    qIcon.addFile(":/Icons/images/icon_off.png",QSize(32,32),QIcon::Normal,QIcon::On);
    qIcon.addFile(":/Icons/images/icon_on.png",QSize(32,32),QIcon::Normal,QIcon::Off);
    toolButton->setIcon(qIcon);
    @

    Hope this help you.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.