March 17, 2012

Kewal Kewal
Lab Rat
37 posts

QIcon; how to change the state and mode?

 

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

  1. QIcon icon;
  2. icon.addFile(":/IconNormal.png", QSize(), QIcon::Normal, QIcon::On);
  3. icon.addFile(":/IconActive.png", QSize(), QIcon::Active, QIcon::On);
  4. icon.addFile(":/IconSelected.png", QSize(), QIcon::Selected, QIcon::On);
  5. 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]

4 replies

March 17, 2012

koahnig koahnig
Mad Scientist
2199 posts

Have a look to this example [qt-project.org]

March 19, 2012

Kewal Kewal
Lab Rat
37 posts

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

March 19, 2012

Andre Andre
Area 51 Engineer
6076 posts

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.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

January 8, 2013

Gouba Gouba
Lab Rat
1 posts

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

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

Hope this help you.

 
  ‹‹ deleteLater() from within activex event handler      Using Qt to generate stringlist combinations ››

You must log in to post a reply. Not a member yet? Register here!