Skip to content

Commit

Permalink
ENH: load stylesheet from file path rather than from string
Browse files Browse the repository at this point in the history
 This makes it possible to use relative icon paths in QSS!
  • Loading branch information
KurtJacobson committed Feb 18, 2020
1 parent ba1410e commit 68c51f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
18 changes: 8 additions & 10 deletions qtpyvcp/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,16 @@ def loadStylesheet(self, stylesheet, watch=False):
"""

def load(path):
with open(path, 'r') as fh:
self.setStyleSheet(fh.read())
LOG.info("Loading global stylesheet: yellow<{}>".format(stylesheet))
self.setStyleSheet("file:///" + path)

LOG.info("Loading QSS stylesheet file: yellow<{}>".format(stylesheet))
load(stylesheet)
if watch:
from qtpy.QtCore import QFileSystemWatcher
self.qss_file_watcher = QFileSystemWatcher()
self.qss_file_watcher.addPath(stylesheet)
self.qss_file_watcher.fileChanged.connect(load)

if watch:
LOG.info("In develop mode, changes to QSS file will automatically be applied")
from qtpy.QtCore import QFileSystemWatcher
self.qss_file_watcher = QFileSystemWatcher()
self.qss_file_watcher.addPath(stylesheet)
self.qss_file_watcher.fileChanged.connect(load)
load(stylesheet)

def loadFont(self, font_path):
"""Loads a font file into the font database. The path can specify the
Expand Down
3 changes: 1 addition & 2 deletions qtpyvcp/widgets/form_widgets/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ def loadStylesheet(self, stylesheet):
stylesheet (str) : Path to a .qss stylesheet
"""
LOG.info("Loading QSS stylesheet file: yellow<{}>".format(stylesheet))
with open(stylesheet, 'r') as fh:
self.setStyleSheet(fh.read())
self.setStyleSheet("file:///" + stylesheet)

def getMenuAction(self, menu_action, title='notitle', action_name='noaction',
args=[], kwargs={}):
Expand Down

0 comments on commit 68c51f3

Please sign in to comment.