views:

273

answers:

2

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?

+1  A: 

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.

graphicdivine
I tried it with double quotes, single quotes, no quotes, including the "background:", and without it. Also, the CSS is *in* the Python source, I'm not using a separate CSS file (I couldn't get that to work. Sue me.) It's as if something more fundamental is wrong. Like I said in the question, according to the strace log, it looks like it's not even *trying* to open the image file.
Enfors
What happens if you give it an absolute url?
graphicdivine
With double quotes, and an absolute path, it *works* - to my great surprise. Problem solved, thanks! But why did the strace log earlier indicate that it wasn't even looking for the file?Ah. I think I get it now. If I remember correctly, strace doesn't trace child processes by default - and it as probably one of those who opened the file.
Enfors
A: 

you could use the background-image like this:

body
{
background-image: url("qrc:///gradient2.jpg");
}