I've developed a text editor using Java and the QtJambi (Qt 4.6.3) library. The application has a QToolBar with some QActions with icons. My text editor can switch between two themes (dark and light). If i use black icons, the dark theme looks terrible, and if I use white icons, the light theme looks terrible too. I want to change the icons when I press the switch theme button.
The icons are declared like this:
private String inir = "classpath:/ico/";
private QIcon iconodeshacer = new QIcon(inir+"deshacer.png");
And I set them to the QActions this way:
private QToolBar herramientas = new QToolBar();
herramientas.addAction(iconodeshacer, "Deshacer", this, "deshacer()");
I've tried to change the inir String and apply:
herramientas.update();
herramientas.repaint();
I can't find a solution for QtJambi or regular Qt (from which I can translate).
I would like to declare both icon themes and apply them without having to declare each QAction outside the configuration and manually change the icon with setIcon();
Thanks to Dmitry Sazonov for giving me an idea. As I'm programming on java, not c++, its code is difficult to apply on my application. But I understood the idea. What I've done its storing the icon names on an String array and resetting the icons of the elements every time i switch the theme.
private String[] nombreiconoseditar = {"copiar.png", "cortar.png", "pegar.png", "", "deshacer.png", "rehacer.png", "", "buscar.png", "buscareemplazar.png"};
And I change the route to the icon folder and set the icon one by one in the element I want, in this example, I change all the icons on the QMenu editar.
inir="classpath:/ico/claro/";
List ed = editar.actions();
for(int i=0; i<ed.size(); i++)
{
QAction tmp = (QAction) ed.get(i);
tmp.setIcon(new QPixmap(inir+nombreiconoseditar[i]));
}
Hope this can help someone with the same problem!