PDA

View Full Version : QToolbar - change icon at runtime ?



pl01
17th November 2010, 16:03
Hi,

In my main window, I have a toolbar with an action. This action/button has an icon (a png image) that is visible in the QT Creator form designer. But when I run the application, I see no image !!! Can you tell me why ?

Also, at run time, with code, I would like to change the image of the toolbar button. Is it possible ? And how to do this ?

Thanks for your help

high_flyer
17th November 2010, 16:33
But when I run the application, I see no image !!! Can you tell me why ?
Has probably to do with path resolution of the image.
But without code its hard to tell exactly.


I would like to change the image of the toolbar button. Is it possible ? And how to do this ?
QAction::setIcon() ?

pl01
17th November 2010, 16:56
Thanks,

I have put my images in ressources and all is fine, it is displayed now.

In order to change the icon I have do this :
actions().first()->setIcon(QIcon(":/images/pause.png"));
But it crash :-P

The problem is that actions(); return an empty list !

FelixB
17th November 2010, 17:17
use the name of the action instead of ations()->first()

pl01
18th November 2010, 08:38
Thanks,

How can I use the name of the action, there is no findAction("") method ?

Also actions() is empty in my main window ! do you know why ?

FelixB
18th November 2010, 09:25
somewhere in your code must be something like this:


QAction myAction;

if you create your form via QtDesigner, you have to create all actions via the action editor. there you give each action a name. You can access your actions the same way as each other gui-element.

produktdotestow
18th November 2010, 18:51
ui->toolBar->actions().first()->setIcon(QIcon(":/images/pause.png"));
?