Get state of a QIcon?
-
Howdy fellow QT'ers folks, hope everyone is doing well. Been playing with creating QIcons for the past week, checked the official docs and don't see how one can fetch the state the icon is currently in?
app.h
private: QIcon goSign;
app.cpp
goSign.addPixmap(QPixmap(":/img/go.png"), QIcon::Normal, QIcon::On); goSign.addPixmap(QPixmap(":/img/stop.png"), QIcon::Normal, QIcon::Off);
I can set the QIcon by using the proper QIcon::State value but can this be fetched afterwards? I figured I could grab the int value of the enum QIcon::State but the QIcon goSign doesn't have a getState function.
Any ideas on how to handle this would be greatly appreciated. Thanks
-
@Calicoder
I agree that from what I can see in the docs there are no getters for theQIcon::Mode
orQIcon::State
: they seem to be passed into constructor/methods only. So if you need that information suggest subclass fromQIcon
and save mode/state into a member variable. Or in your case I think you just need to create a wrapper class for theQPixmap
you create saving the icon state/mode with it. -
@Calicoder
Further, it's not really aQIcon
which has the state or mode. It is that it can generate icons for them from the pixmaps it has available.A QIcon can generate smaller, larger, active, and disabled pixmaps from the set of pixmaps it is given. Such pixmaps are used by Qt widgets to show an icon representing a particular action.
You went
goSign.addPixmap(QPixmap(":/img/go.png"), QIcon::Normal, QIcon::On);
So it's the
QPixmap
you are adding which has theNormal
/On
attributes.