|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a main window class with styling support. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtWidgets import QMainWindow, QStyleFactory, QApplication |
|
11 |
|
12 from .EricApplication import ericApp |
|
13 |
|
14 |
|
15 class EricMainWindow(QMainWindow): |
|
16 """ |
|
17 Class implementing a main window with styling support. |
|
18 """ |
|
19 def __init__(self, parent=None): |
|
20 """ |
|
21 Constructor |
|
22 |
|
23 @param parent reference to the parent widget |
|
24 @type QWidget |
|
25 """ |
|
26 super().__init__(parent) |
|
27 |
|
28 self.defaultStyleName = QApplication.style().objectName() |
|
29 |
|
30 def setStyle(self, styleName, styleSheetFile): |
|
31 """ |
|
32 Public method to set the style of the interface. |
|
33 |
|
34 @param styleName name of the style to set |
|
35 @type str |
|
36 @param styleSheetFile name of a style sheet file to read to overwrite |
|
37 defaults of the given style |
|
38 @type str |
|
39 """ |
|
40 # step 1: set the style |
|
41 style = None |
|
42 if styleName != "System" and styleName in QStyleFactory.keys(): |
|
43 # __IGNORE_WARNING_Y118__ |
|
44 style = QStyleFactory.create(styleName) |
|
45 if style is None: |
|
46 style = QStyleFactory.create(self.defaultStyleName) |
|
47 if style is not None: |
|
48 QApplication.setStyle(style) |
|
49 |
|
50 # step 2: set a style sheet |
|
51 ericApp().setStyleSheetFile(styleSheetFile) |