Qt stylesheet, background image from filepath

后端 未结 1 1084
野性不改
野性不改 2020-12-19 23:14

All examples I have found so far refer to background images in the resource file. Something like:

 QFrame {
     background-image: url(:/images/header.png);
         


        
相关标签:
1条回答
  • 2020-12-19 23:34

    You don't necessarily need add your files as resources. Try this for example:

    QFrame{background-image: url("C:/temp/foo.jpg");}
    

    Note the standard slashes, like you'd use in a URL—they're not Windows' back-slashes. So this, for example, will not work:

    QFrame{background-image: url("C:\\temp\\foo.jpg");} /* Won't work! */
    

    Windows' back-slashes are invalid in QSS, even when you escape them.

    You could also use a relative path:

    QFrame{background-image: url("temp/foo.jpg");}
    

    Be careful, though, because the path is relative to the CWD at runtime, which the user might change.

    0 讨论(0)
提交回复
热议问题