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. Correct syntax for local image file?
Forum Updated to NodeBB v4.3 + New Features

Correct syntax for local image file?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 5 Posters 1.6k Views 2 Watching
  • 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    What is the correct syntax for an image file to be used with setStyleSheet ?

    I've tried this:

    background-image:url('file://Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png');
    

    When I pass this to setStyleSheet, I see:

    Could not create pixmap from file://Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png
    

    In the Application output, I've also tried:

    background-image:url('file:///Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png');
    

    and

    In the Application output, I've also tried:

    background-image:url('://Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png');
    

    and

    background-image:url(':/Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png');
    

    Same result. By the way, I'm working on an iMAC.

    Kind Regards,
    Sy

    J.HilkJ jsulmJ 2 Replies Last reply
    0
    • SPlattenS SPlatten

      What is the correct syntax for an image file to be used with setStyleSheet ?

      I've tried this:

      background-image:url('file://Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png');
      

      When I pass this to setStyleSheet, I see:

      Could not create pixmap from file://Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png
      

      In the Application output, I've also tried:

      background-image:url('file:///Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png');
      

      and

      In the Application output, I've also tried:

      background-image:url('://Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png');
      

      and

      background-image:url(':/Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png');
      

      Same result. By the way, I'm working on an iMAC.

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

      @SPlatten
      this:

      background-image:url("/Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png");
      

      should work:
      Simple file path with full quotation marks


      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.

      1 Reply Last reply
      1
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #2

        I've not done it before, but isn't the resrouce locator format of :/path relative to the project top dir? Is the image compiled into the app, or expected to be accessed as a standalone support file, delivered with the app?

        1 Reply Last reply
        0
        • SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #3

          @Kent-Dorfman , these images are not built into the project the resources are designed to be on the local file system.

          Kind Regards,
          Sy

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Bonnie
            wrote on last edited by
            #4

            I'm currently not with a MAC so I can't test.
            But did you try just "/Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png"?

            1 Reply Last reply
            0
            • SPlattenS SPlatten

              What is the correct syntax for an image file to be used with setStyleSheet ?

              I've tried this:

              background-image:url('file://Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png');
              

              When I pass this to setStyleSheet, I see:

              Could not create pixmap from file://Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png
              

              In the Application output, I've also tried:

              background-image:url('file:///Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png');
              

              and

              In the Application output, I've also tried:

              background-image:url('://Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png');
              

              and

              background-image:url(':/Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png');
              

              Same result. By the way, I'm working on an iMAC.

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

              @SPlatten
              this:

              background-image:url("/Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png");
              

              should work:
              Simple file path with full quotation marks


              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.

              1 Reply Last reply
              1
              • SPlattenS SPlatten

                What is the correct syntax for an image file to be used with setStyleSheet ?

                I've tried this:

                background-image:url('file://Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png');
                

                When I pass this to setStyleSheet, I see:

                Could not create pixmap from file://Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png
                

                In the Application output, I've also tried:

                background-image:url('file:///Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png');
                

                and

                In the Application output, I've also tried:

                background-image:url('://Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png');
                

                and

                background-image:url(':/Users/simonplatten/XMLMPAM/config/images/meshtile_4x4.png');
                

                Same result. By the way, I'm working on an iMAC.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @SPlatten As shown here: https://doc.qt.io/Qt-5/stylesheet-syntax.html there is no need for ''.
                Also keep in mind that using absolute paths prevents your app from working properly on other machines...

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                3
                • SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by SPlatten
                  #7

                  @jsulm, although there is a default path that the application will use, it can also be overridden with a command line argument, once the application knows where to locate the configuration file (XML), everything else is specified in the XML.

                  The CSS contains just the file name, not the path, the application processes the CSS and if it finds a URI reference then it corrects the file spec. using the configured path.

                  Kind Regards,
                  Sy

                  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