QToolbar - change icon at runtime ?
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
Re: QToolbar - change icon at runtime ?
Quote:
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.
Quote:
I would like to change the image of the toolbar button. Is it possible ? And how to do this ?
QAction::setIcon() ?
Re: QToolbar - change icon at runtime ?
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 :
Code:
actions
().
first()->setIcon
(QIcon(":/images/pause.png"));
But it crash :-P
The problem is that actions(); return an empty list !
Re: QToolbar - change icon at runtime ?
use the name of the action instead of ations()->first()
Re: QToolbar - change icon at runtime ?
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 ?
Re: QToolbar - change icon at runtime ?
somewhere in your code must be something like this:
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.
Re: QToolbar - change icon at runtime ?
Code:
ui
->toolBar
->actions
().
first()->setIcon
(QIcon(":/images/pause.png"));
?