src/eric7/EricWidgets/EricMainWindow.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
diff -r 3fc8dfeb6ebe -r b99e7fd55fd3 src/eric7/EricWidgets/EricMainWindow.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/eric7/EricWidgets/EricMainWindow.py	Thu Jul 07 11:23:56 2022 +0200
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2012 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a main window class with styling support.
+"""
+
+from PyQt6.QtWidgets import QMainWindow, QStyleFactory, QApplication
+
+from .EricApplication import ericApp
+
+
+class EricMainWindow(QMainWindow):
+    """
+    Class implementing a main window with styling support.
+    """
+    def __init__(self, parent=None):
+        """
+        Constructor
+        
+        @param parent reference to the parent widget
+        @type QWidget
+        """
+        super().__init__(parent)
+        
+        self.defaultStyleName = QApplication.style().objectName()
+    
+    def setStyle(self, styleName, styleSheetFile):
+        """
+        Public method to set the style of the interface.
+        
+        @param styleName name of the style to set
+        @type str
+        @param styleSheetFile name of a style sheet file to read to overwrite
+            defaults of the given style
+        @type str
+        """
+        # step 1: set the style
+        style = None
+        if styleName != "System" and styleName in QStyleFactory.keys():
+            # __IGNORE_WARNING_Y118__
+            style = QStyleFactory.create(styleName)
+        if style is None:
+            style = QStyleFactory.create(self.defaultStyleName)
+        if style is not None:
+            QApplication.setStyle(style)
+        
+        # step 2: set a style sheet
+        ericApp().setStyleSheetFile(styleSheetFile)

eric ide

mercurial