Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Correct syntax for local image file?



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


  • Moderators

    @SPlatten
    this:

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

    should work:
    Simple file path with full quotation marks



  • 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?



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



  • 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"?


  • Moderators

    @SPlatten
    this:

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

    should work:
    Simple file path with full quotation marks


  • Lifetime Qt Champion

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



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


Log in to reply