Solved How to change the icon of the actions on ToolBar during runtime?
-
I want to design an action, like the control buttons of a media player, when I click the start button, the button becomes a pause button.
I have set the default action icon, when I try to change it, use codes following:
ui->actionConnect->setIcon(QIcon(":/resources/disconnect.ico"));
I found the icon will become empty.
So what's the right method? :( -
That should do it. Are you sure the path is correct?
-
@sheeley The icon file must be JPG or PNG
-
@raf924 No. It doesn't. It can be any of the supported image formats or anything that you add via imageformat plugin.
-
@Chris-Kawa Yes yes you're right i misspoke. what i meant was that it would work with another format by giving two widely-used formats. But indeed it would work with the formats given in the link
-
@Chris-Kawa Thanks for your reply.
The folder tree is as follows:
Project Folder
.....mainWindow.cpp
.....others cpp files
.....resources <- This is a folder.
..........disconnect.icoThe codes above are in the mainWindpw.cpp, so was the path right?
-
Hi,
Did you put disconnect.ico in Qt's resource system ? Otherwise that's the first problem you have with the path you used in you sample code.
-
@SGaist Thank you.
I mistook the resources prefix. It works now.