[PyQt] StyleSheet relative path

Hans-Peter Jansen hpj at urpla.net
Thu May 5 23:26:59 BST 2011


On Thursday 05 May 2011, 21:19:50 Hugo Léveillé wrote:
> Hi
>
> Lets say I have a styleheet and an image file in the same folder
>
>  QTextEdit, QListView {
>      background-color: white;
>      background-image: url(myImage.png);
>      background-attachment: scroll;
>  }
>
> I expected this to work since they are at the same level but I still
> have to type the whole path like so:
>
>  QTextEdit, QListView {
>      background-color: white;
>      background-image: url(/path/to/my/file/myImage.png);
>      background-attachment: scroll;
>  }
>
> What would be the correct syntax to make the filename relative to the
> stylesheet so that the image will load on any machine no matter the
> root path

No idea, but have you checked:
	- QDir.currentPath()
	- prepending ./
	- using Qt's resource system

Pete




More information about the PyQt mailing list