Set icon on qpushbutton

I know this is a newbie question, but I should try to solve it with goolge / stackoverflow, but I did not find a good answer. The problem is that I want to add an icon in qpushbutton. But this does not work / file not found?!, Where is the problem?

... about the file

[...]OTHER_FILES += \
Readme.txt \
icons/newFolder.png \
icons/newFile.png 

class.cpp

//toolbar
QToolBar *tool = new QToolBar();
QPushButton *btn = new QPushButton();
btn->setIcon(QIcon(":/icons/newFile.png"));

tool->addWidget(btn);
addToolBar(tool);

Best regards: D Chris

+4
source share
1 answer

Adding PNG files to your project has no effect. You need to create a resource file and add your files to it. After that, you can access resource data using notation ":/icons/newFile.png".

See Qt Resource System .

+5
source

All Articles