Correct way to load external qt stylesheet

well I came up with this code work fine but is this the correct way to load a external stylesheet into PyQt ?


sshFile="darkorange.stylesheet"
fh = open(sshFile,"r")
qstr = QtCore.QString(fh.read())
self.setStyleSheet(qstr) 

i just dont want to do anything wrong :rolleyes:

Yup, that’s the way to do it.
Though I would change a few things, mostly with how you handle variables:
*sshFile as a var name is potentially going to cause confusion with whoever gets it (ssh being a common protocol).
*you could just use fh to replace qstr ( fh = open(file).read() ) , which will also let you reuse the stylesheet without multiple reads.
*Python always opens in read only mode by default, though I guess being explicit is good etiquette
*I would not use qstr as a variable name mainly because variables should infer their purpose not only their type.

yesterday I testing my app on my friends desktop and got IO error saying darkorange.stylesheet not found so I utilized the file to get the path in the same root to be precise, and now I have code like this:

        
        styleFile=os.path.join(os.path.split(__file__)[0],"darkorange.stylesheet")
        styleSheetStr = QtCore.QString(open(styleFile,"r").read())
        self.setStyleSheet(styleSheetStr)