Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Accessing resources (.png etc.) that are part of qrc through stylesheet (.qss) which is not part of .qrc
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 4.8k Views
  • 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 Offline
    R Offline
    Rachit
    wrote on last edited by
    #1

    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
    0
    • R Offline
      R Offline
      raf924
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rachit
        wrote on last edited by
        #3

        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
        0
        • R Offline
          R Offline
          raf924
          wrote on last edited by
          #4

          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
          0
          • R Offline
            R Offline
            Rachit
            wrote on last edited by
            #5

            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
            0
            • R Offline
              R Offline
              raf924
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • B Offline
                B Offline
                butterface
                wrote on last edited by
                #7

                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
                0
                • R Offline
                  R Offline
                  Rachit
                  wrote on last edited by
                  #8

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

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved