I'm building a small program using pyQt and pyInstaller. I've tried to add an background image to my QMainWindow:
class pyPrimaMainWindow(QMainWindow):
def __init__(self):
...do some stuff...
self.setWindowIcon(QIcon(os.path.join(self.py_prima.resource_path(), "TH.ico"))) # <- this works
self.setStyleSheet("QMainWindow{{border-image: url({0});background-size:100%;}}".format(os.path.join(self.py_prima.resource_path(), "bg.png")))
The resource_path() methods looks like that:
def resource_path(self):
""" Get absolute path to resource, works for dev and for PyInstaller """
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = getattr(sys, '_MEIPASS', "C:/Users/Tobias/eclipse/workspace/PyPrima/data/")
# except Exception:
# base_path =
print(base_path)
return base_path
It's copied from the pyinstaller wiki, returns an absoulte path and works for other pictures/icons. However, if I build an executable with pyInstaller, the programm runs nice, but the background image is missing. Instead, the console outputs
"could not parse stylesheet of object ..."
If I run the python file, it works all fine...
Any ideas on this?
Thanks!