简体   繁体   中英

Qt background-image shows in designer but not in release

I have a simple Qt GUI application and I am having trouble setting the image background. The background image displays properly in form editor/designer but when I run the application there is no background image.

Resource file:

<RCC>
    <qresource prefix="/">
        <file>eb_back_small.png</file>
        <file>favicon.ico</file>
        <file>background.jpg</file>
    </qresource>
</RCC>

This is how it looks like in editor: 表格编辑

Style sheet for centralWidget (background.jpg is a simple 500x350 red image):

#centralWidget {    
    background-image: url(:/background.jpg);
}

Style sheet for widget (just to see if background-color works because I assume something is not right with my resources):

#widget {
    background-color: rgb(0, 170, 0);
}

And this is the final result when I run the app: 发布

I assume somehow the build cannot access the background image resource but I have no idea why. I also tried to apply general background-image property in Window0 style sheet but it does not change anything (for example, if main window was overwriting the background but it does not seem to be the case).

Read article about application deployment in Qt assistant. I guess you don't have image plugins on target computer. Folder plugins/images and your exe should be in one directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM