PyQt WebKit CSS background image not showing
I'm making a Twitter client with PyQt, which uses WebKit to draw the tweet list. Now I'm trying to use CSS to set a background image in the WebKit widget - but the image won't show up. This is the relevant part of the CSS:
body
{
background-image: url("gradient2.jpg");
}
The file name is correctly spelled, and it is located in the same directory as the Python program, which is also where I start the program from (so the image file should be in PWD).
To check if WebKit somehow looks for the image in the wrong directory anyway, I ran my program through strace, which creates a log of all system calls made by the program. And surprisingly, the name of the image does not appear in the log - so it seems as if WebKit doesn't even try to find it.
To verify that my CSS is used at all by WebKit, I tried changing it to a solid background color instead of an image:
body
{ 开发者_如何学运维
background: #CCFFCC;
}
And that works. So I know that the CSS is used, that's not the problem.
Could it be that WebKit refuses to use "ordinary" files in the filesystem, and that I somehow have to create some sort of "resource" file containing my image in Qt Designer?
Try removing the quotes. Also, bear in mind that if you declare a "background:" shorthand rule after a "backround-image:" rule, the background-image will be overwritten. Also, the file path should be relative to the css file, not the source file.
you could use the background-image like this:
body
{
background-image: url("qrc:///gradient2.jpg");
}
精彩评论