Skip to content

Instantly share code, notes, and snippets.

@anddam
Created January 11, 2021 23:29
Show Gist options
  • Save anddam/c671d3592c10131c0ebeb8bafef0f7f7 to your computer and use it in GitHub Desktop.
Save anddam/c671d3592c10131c0ebeb8bafef0f7f7 to your computer and use it in GitHub Desktop.
class QSelfLoadingWidgetMixin:
"""Load UI and CSS files into current instance
Expects a dict containing "ui" mandatory and "css" optional keys.
"""
def __init__(self, resource_files=None, parent=None):
super().__init__(parent)
if resource_files:
ui_file = resource_files.get("ui")
css_file = resource_files.get("css")
else:
ui_file, css_file = None, None
if ui_file:
loadUi(ui_file, self)
if css_file:
with open(css_file) as css_file:
self.setStyleSheet(css_file.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment