Reading pyqt stylesheet from external qss file
Asked Answered
M

2

11

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?

Marte answered 24/1, 2013 at 17:6 Comment(0)
M
31

Figured out the answer:

sshFile="darkorange.stylesheet"
with open(sshFile,"r") as fh:
    self.setStyleSheet(fh.read())
Marte answered 24/1, 2013 at 17:16 Comment(1)
You don't need to make it a QString and better to close the fh or use with. I've edited your post.Jugulate
S
0

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)
Steinman answered 16/11, 2023 at 11:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.