Accessing resources (.png etc.) that are part of qrc through stylesheet (.qss) which is not part of .qrc
In my application, I am having a qss file, but this is not part of the QT resources (.qrc). I have some .png files that are part of my .qrc file. But when I use any of the .png files in my .qss file like image: url(:/my_qrc_prefix/my_resource.png), it does not work.
Where as when I make .qss file part of the .qrc file, then it works. Unfortunately I have a need to not to make the .qss file not part of .qrc.
Is it possible to access the .png files that are referred in .qrc as I mentioned above.
I also tried, by not making .qss part of .qrc and then accessing something on hard drive, that works.
Any help is highly appreciated.
A question : Why exactly can't you put your qss file in the ressources?
The reason is the way I am using style sheet is a little tricky ;-)
I have one #if macro GUI_DESIGN_MODE, when it is ON, I update my .qss file and in my source code I use a QFileSystemWatcher, that applies it on the qApp. This makes my UI styling super fast. If my .qss becomes part of .qrc, then I will not be able to do that, as by using .qrc, the resources become part of the .exe and there is no link to any file on hard drive.
When macro GUI_DESIGN_MODE is OFF (in release mode), I use my .qss as a resource (so no QFileSystemWatcher act) and can refer to the .png files from the .qrc file.
So at the end I want to have a win-win situation where when the mode is ON, i should be able to refer any .png file in my .qss and see how it looks on UI (without restarting the application)
OK I see. Well the only way I can think of to resolve your issue is to dynamically copy your png files from your ressources to your hard drive. It's not a very clean way but if there is another i can't see it. Wait for someone else to answer before considering my solution.
Well, that will not work as in my .qss file, I am referring to resources as url(:/my_qrc_prefix/my_resource.png), even if i copy the resources to hard drive, I still will not be able to refer them as they are part of .qrc.
OR if I copy it as you mentioned, then the problem is I have to refer them giving some hard drive path. And once my styling is done, I have to manually (or by writing a new parser and using it) replace the .png path from hard disk to the path of .qrc.
Whereas I don't understand why it does not work that I cannot refer resource from .qrc (as it is up and active when my executable is running) from the .qss that is not part of .qrc
Or you can use 2 qss file one with the ressource path and the other with the hard drive path
You can use relative paths. Then it should not depend on your step in design process. You also don't need to go back to the qrc but using the copied file.
On the other hand I don't think that is a very good way of working if your development code is different in a very basic way compared to the release code (for example you are testing completely different things then).
@butterface: Good Idea for relative path. I used it and fixed the problem.
On the other hand, my source code is exactly same in debug/release mode. Only the design mode macro i turn it ON/OFF. Also while designing I do it in release mode by design mode ON. So from UI side, developed and tested part are same. Just this makes the development fastest (as of my knowledge). Not sure if there are even options.