Reputation: 8277
I have made a qss file of pyqt stylsheet and how am I supposed to call the file content and feed to self.setStylesheet(..)
?
from PyQt4 import QtCore
s = QtCore.QString('c:\myProject\darkFantasy.stylesheet')
The above code loads the path string rather than the actual stylesheet.
So how do I load the actual content of the stylesheet file? Should I read it using the open file in read mode?
Upvotes: 11
Views: 18170
Reputation: 8277
Figured out the answer:
sshFile="darkorange.stylesheet"
with open(sshFile,"r") as fh:
self.setStyleSheet(fh.read())
Upvotes: 31
Reputation: 1
Using Pyqt And Pyside load stylesheet css file
#load file
styleFile = QFile('stylesheet/style.css')
#set file mode
styleFile.open(QFile.OpenModeFlag.ReadOnly)
#convert QbyteArray to String
convert = styleFile.readAll().toStdString()
#set stylesheet
self.setStyleSheet(convert)
Upvotes: 0