2016-07-22 12 views
0

Ich baue ein kleines Programm mit pyQt und pyInstaller. Ich habe versucht, ein Hintergrundbild zu meinem QMainWindow hinzuzufügen:pyinstaller "konnte Stylesheet nicht analysieren"

sieht
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"))) 

Die resource_path() Methoden wie folgt aus:

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 

Aus dem pyinstaller Wiki kopiert wird, gibt einen absoulte Weg und Werke für andere Bilder/Icons. Allerdings, wenn ich eine ausführbare Datei mit pyInstaller erstellen, läuft das Programm schön, aber das Hintergrundbild fehlt. Stattdessen werden die Konsolausgaben

"could not parse stylesheet of object ..." 

Wenn ich die Python-Datei ausführen, funktioniert es alles in Ordnung ...

Irgendwelche Ideen dazu?

Danke!

Antwort

0

Ich beantworte meine eigene Frage für den Fall, dass jemand anderes auf dasselbe Problem stößt.

Die fileseparators falsch sind ... Fix it mit

bgpath = os.path.join(self.py_prima.resource_path(), "bg.png") 
bgpath = bgpath.replace("\\", "/") 
self.setStyleSheet("QMainWindow{{border-image: url({0});background-size: 100%;}}".format(
     bgpath)) 
Verwandte Themen