Set icon on qpushbutton
Asked Answered
T

1

6

I know, thats a beginners question but I have to tried to solve it with goolge / stackoverflow, but I haven't found a good answer. The problem is, I want to add a icon to a qpushbutton. But it doesnt work / the file is not found?!, where is the problem?

...pro-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

Twiggy answered 3/11, 2013 at 23:15 Comment(0)
D
5

Adding PNG files to your project doesn't have any effect. You need to create a resource file and add your files to it. After doing this you can access resource data using ":/icons/newFile.png" notation.

See The Qt Resource System.

Deranged answered 3/11, 2013 at 23:17 Comment(1)
This helped... but it still still didn't work for me until I deleted the output directory and recompiled (even cleaning didn't work).Letty

© 2022 - 2024 — McMap. All rights reserved.