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. Image source
Forum Update on Monday, May 27th 2025

Image source

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.6k 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.
  • D Offline
    D Offline
    David King
    wrote on last edited by David King
    #1

    Hi,

    Background images don't show in Qt Creator unless you specify the full path. Anyone know a workaround ?

    They show fine at runtime without a path.

    So this in a styleSheet is fine for runtime:

    background-image:url(foo.png);
    

    But to see my foo at designtime, I must have:

    background-image:url(C:/I/Am/Here/foo.png);
    

    Which isn't great for portability of source:
    Bites me as working from OneDrive, which has a different path on my two work PCs:

    C:\Users\PC1\OneDrive\
    C:\Users\PC2\OneDrive\
    

    I'm afraid, I can't use resources, to avoid this pathing problem - it's a Qt Script world only for us, due to the vendor utility sandbox we live in.

    Infact, is it possible with Qt, to embed image data in the .xml ?
    Say, in a text property that allows HTML, such as QLabel text ?
    Something like the following, which you can do in full HTML:

    <img src="data:image/png;base64,iVBORw0KG ... 5ErkJggg=="/>
    

    Or alternatively, in a styleSheet property thus, which you can do in full CSS ?

    background-image:url(data:image/png;base64,iVBORw0KG ... 5ErkJggg==)
    

    Or, have my Qt Script .js code populate one or other of those properties ?

    Best regards,

    David

    J.HilkJ 1 Reply Last reply
    0
    • D David King

      Hi,

      Background images don't show in Qt Creator unless you specify the full path. Anyone know a workaround ?

      They show fine at runtime without a path.

      So this in a styleSheet is fine for runtime:

      background-image:url(foo.png);
      

      But to see my foo at designtime, I must have:

      background-image:url(C:/I/Am/Here/foo.png);
      

      Which isn't great for portability of source:
      Bites me as working from OneDrive, which has a different path on my two work PCs:

      C:\Users\PC1\OneDrive\
      C:\Users\PC2\OneDrive\
      

      I'm afraid, I can't use resources, to avoid this pathing problem - it's a Qt Script world only for us, due to the vendor utility sandbox we live in.

      Infact, is it possible with Qt, to embed image data in the .xml ?
      Say, in a text property that allows HTML, such as QLabel text ?
      Something like the following, which you can do in full HTML:

      <img src="data:image/png;base64,iVBORw0KG ... 5ErkJggg=="/>
      

      Or alternatively, in a styleSheet property thus, which you can do in full CSS ?

      background-image:url(data:image/png;base64,iVBORw0KG ... 5ErkJggg==)
      

      Or, have my Qt Script .js code populate one or other of those properties ?

      Best regards,

      David

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      @David-King when you can't use ressources, like you said, I would suggest looking at
      QStandardPaths you should be able to work with that, I think.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      D 1 Reply Last reply
      1
      • J.HilkJ J.Hilk

        @David-King when you can't use ressources, like you said, I would suggest looking at
        QStandardPaths you should be able to work with that, I think.

        D Offline
        D Offline
        David King
        wrote on last edited by David King
        #3

        Hi J.Hilk, thanks for your reply there, much appreciated. I've just taken a look at the StandardPaths help. Looks interesting, but unfortunately, from our .js sandbox, we can use only signals, slots, accessible properties, and attributes. Though sandbox might have an issues with attribute, jury out on that. Thanks anyway. David

        1 Reply Last reply
        0
        • D Offline
          D Offline
          David King
          wrote on last edited by David King
          #4

          Hi folks,

          I've just tried base64 embedding. CSS didn't work, but HTML did, so I'm now path free :-)
          And that indeed accords with the Qt CSS and HTML reference info, now I've taken a proper look.

          Oh and images now show at designtime, and runtime on both my work PCs :-)

          I randomly googled for base64 encode, and landed at https://www.base64encode.org/
          onto which I dropped my pngs, it downloaded back at me a text equivalent.
          It formats at 76 characters-per-line, I'm happy with that, no mile-long strings.

          My icon .png remains an external file, but that's fine as Qt uses for that, just MyIcon.png,
          not C:/I/Am/Here/MyIcon.png

          So solved? Well found a different way. We could do with a 'Workedaround' button..

          Best regards,

          David

          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