Solved set qicon to qpushbutton
-
i'm trying to set an icon to qpushbutton, and the image for the icon is in the same directory as this source file, but it won't show up on the button. however, if i put the image in the root directory and specify the full path for it, say "C:\\1.png", the image will show up.
why is this? and how can i set an icon from current directory (or say, one directory above)? i've tried "./1.png" which didn't work.
thanks.
#include <QApplication> #include <QPushButton> #include <QIcon> int main(int argc, char **argv) { QApplication app(argc, argv); QIcon icon("1.png"); QPushButton button; button.setIcon(icon); button.show(); return app.exec(); }
-
Hi..
You must add your png in resource file and then insert url in brackets.
QIcon icon(":/new/ok.png"); QPushButton *button = new QPushButton(this); button->setIcon(icon); button->show();