Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Accessing resources (.png etc.) that are part of qrc through stylesheet (.qss) which is not part of .qrc

    General and Desktop
    3
    8
    4259
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      Rachit last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • R
        raf924 last edited by

        A question : Why exactly can't you put your qss file in the ressources?

        1 Reply Last reply Reply Quote 0
        • R
          Rachit last edited by

          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)

          1 Reply Last reply Reply Quote 0
          • R
            raf924 last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • R
              Rachit last edited by

              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

              1 Reply Last reply Reply Quote 0
              • R
                raf924 last edited by

                Or you can use 2 qss file one with the ressource path and the other with the hard drive path

                1 Reply Last reply Reply Quote 0
                • B
                  butterface last edited by

                  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).

                  1 Reply Last reply Reply Quote 0
                  • R
                    Rachit last edited by

                    @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.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post