QFrame setStyleSheet background-image not working on Windows
-
Hi,
frame = QFrame()
frame.setStyleSheet("background-image:url(<path-to-png-image>); background-position:center; background-repeat:no-repeat;")is working on MacOs but not on Windows.
Does anyone has an idea, why?
@retconx said in QFrame setStyleSheet background-image not working on Windows:
Does anyone has an idea, why?
Well, what exactly is path-to-png-image? Where is the image stored?
-
@retconx said in QFrame setStyleSheet background-image not working on Windows:
Does anyone has an idea, why?
Well, what exactly is path-to-png-image? Where is the image stored?
-
@jsulm
It is stored in an folder "pictures" in the main application folder:basedir = os.path.dirname(__file__)
os.path.join(basedir, "pictures", "image.png")path-to-png-image is a .png-file
-
@jsulm
It is stored in an folder "pictures" in the main application folder:basedir = os.path.dirname(__file__)
os.path.join(basedir, "pictures", "image.png")path-to-png-image is a .png-file
-
@retconx Did you make sure the path is valid?
You also did not show how you put the path into the style-sheet.@jsulm The original code line is:
frame.setStyleSheet("background-image:url(" + os.path.join(basedir, "pictures", "image.png") + "); background-position:center; background-repeat:no-repeat;")Pasting the output of print(os.path.join(basedir, "pictures", "image.png")) to Windows Explorer opens the picture. So the path should be valid.
-
@jsulm The original code line is:
frame.setStyleSheet("background-image:url(" + os.path.join(basedir, "pictures", "image.png") + "); background-position:center; background-repeat:no-repeat;")Pasting the output of print(os.path.join(basedir, "pictures", "image.png")) to Windows Explorer opens the picture. So the path should be valid.
-
@retconx I'm not sure but maybe the problem is that Windows paths contain back-slashes? Try to put the same path but with forward slashes directly (just to see whether it makes a difference).
@jsulm No difference, unfortunately.
That is acutally the reason why I use os.path.join in order to get backslashes for Windows an forwardslashes for Mac/Linux.
And as I said, the path with backslashes works in Windows Explorer.Maybe it has to do with any QFrame properties (shape, style...) which have to be set in Windows to show background-images? I will try a bit...