PDA

View Full Version : Can't change toolbutton icon



waynew
7th November 2010, 23:30
I have a toolbutton created in Designer with an action actionEdits.
Made it a toggle button with a little code. Would like to change the icon when it toggles. The icon from Designer comes up fine when the application starts, but when you click the icon, it disappears as the code tries to change it.

The icon files are both in a directory <application-root>/images and listed in the qrc with all my other icons. Yes, I did run qmake after adding them.
And


QDirIterator it(":", QDirIterator::Subdirectories);
while (it.hasNext())
qDebug() << it.next();

Shows they are there.
Here is the code for changing the icon on toggle, but it is obviously not working since the icon disappears on the first click.


ui->actionEdits->setIcon(QIcon("./images/application_edit.png"));

So what could be wrong here?

tbscope
8th November 2010, 05:37
Here is the code for changing the icon on toggle, but it is obviously not working since the icon disappears on the first click.


ui->actionEdits->setIcon(QIcon("./images/application_edit.png"));

So what could be wrong here?

Can that image be found?

waynew
8th November 2010, 12:47
Yes, I can view the icon images in the images directory with a graphics program, and this code:


QDirIterator it(":", QDirIterator::Subdirectories);
while (it.hasNext())
qDebug() << it.next();


Yields this:
":/images"
":/images/application_edit.png"
":/images/undo.png"
":/images/new.png"
":/images/info.png"
":/images/page_red.png"
":/images/copy.png"
":/images/close.png"
":/images/open.png"
":/images/message.png"
":/images/viewdetailed-32.png"
":/images/save.png"
":/images/paste.png"
":/images/cut.png"
":/images/quit.png"
":/images/standardbutton-save-32.png"
":/images/1uparrow.png"
":/images/consoleButtonGlyph.png"
":/images/1downarrow.png"

waynew
9th November 2010, 00:43
Update: if I put in an absolute path, it works. But why not relative?

zim
8th December 2010, 09:37
Thanx for this thread.