stylesheet_patcher.py (1737B)
1 """This is used to patch the QApplication style sheet. 2 It reads the current stylesheet, appends our modifications and sets the new stylesheet. 3 """ 4 5 import sys 6 7 from PyQt5 import QtWidgets 8 9 10 CUSTOM_PATCH_FOR_DARK_THEME = ''' 11 /* PayToEdit text was being clipped */ 12 QAbstractScrollArea { 13 padding: 0px; 14 } 15 /* In History tab, labels while edited were being clipped (Windows) */ 16 QAbstractItemView QLineEdit { 17 padding: 0px; 18 show-decoration-selected: 1; 19 } 20 /* Checked item in dropdowns have way too much height... 21 see #6281 and https://github.com/ColinDuquesnoy/QDarkStyleSheet/issues/200 22 */ 23 QComboBox::item:checked { 24 font-weight: bold; 25 max-height: 30px; 26 } 27 ''' 28 29 CUSTOM_PATCH_FOR_DEFAULT_THEME_MACOS = ''' 30 /* On macOS, main window status bar icons have ugly frame (see #6300) */ 31 StatusBarButton { 32 background-color: transparent; 33 border: 1px solid transparent; 34 border-radius: 4px; 35 margin: 0px; 36 padding: 2px; 37 } 38 StatusBarButton:checked { 39 background-color: transparent; 40 border: 1px solid #1464A0; 41 } 42 StatusBarButton:checked:disabled { 43 border: 1px solid #14506E; 44 } 45 StatusBarButton:pressed { 46 margin: 1px; 47 background-color: transparent; 48 border: 1px solid #1464A0; 49 } 50 StatusBarButton:disabled { 51 border: none; 52 } 53 StatusBarButton:hover { 54 border: 1px solid #148CD2; 55 } 56 ''' 57 58 59 def patch_qt_stylesheet(use_dark_theme: bool) -> None: 60 custom_patch = "" 61 if use_dark_theme: 62 custom_patch = CUSTOM_PATCH_FOR_DARK_THEME 63 else: # default theme (typically light) 64 if sys.platform == 'darwin': 65 custom_patch = CUSTOM_PATCH_FOR_DEFAULT_THEME_MACOS 66 67 app = QtWidgets.QApplication.instance() 68 style_sheet = app.styleSheet() + custom_patch 69 app.setStyleSheet(style_sheet)