Browse Source

qt StatusBarButton: use custom theme for macOS if using default theme

patch-4
SomberNight 4 years ago
parent
commit
5b9c972499
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/gui/qt/main_window.py
  2. 72
      electrum/gui/qt/stylesheet_patcher.py

2
electrum/gui/qt/main_window.py

@ -104,7 +104,9 @@ if TYPE_CHECKING:
LN_NUM_PAYMENT_ATTEMPTS = 10 LN_NUM_PAYMENT_ATTEMPTS = 10
class StatusBarButton(QToolButton): class StatusBarButton(QToolButton):
# note: this class has a custom stylesheet applied in stylesheet_patcher.py
def __init__(self, icon, tooltip, func): def __init__(self, icon, tooltip, func):
QToolButton.__init__(self) QToolButton.__init__(self)
self.setText('') self.setText('')

72
electrum/gui/qt/stylesheet_patcher.py

@ -2,32 +2,68 @@
It reads the current stylesheet, appends our modifications and sets the new stylesheet. It reads the current stylesheet, appends our modifications and sets the new stylesheet.
""" """
from PyQt5 import QtWidgets import sys
def patch_qt_stylesheet(use_dark_theme: bool) -> None: from PyQt5 import QtWidgets
if not use_dark_theme:
return
app = QtWidgets.QApplication.instance()
style_sheet = app.styleSheet() CUSTOM_PATCH_FOR_DARK_THEME = '''
style_sheet = style_sheet + ''' /* PayToEdit text was being clipped */
/* PayToEdit text was being clipped */ QAbstractScrollArea {
QAbstractScrollArea {
padding: 0px; padding: 0px;
} }
/* In History tab, labels while edited were being clipped (Windows) */ /* In History tab, labels while edited were being clipped (Windows) */
QAbstractItemView QLineEdit { QAbstractItemView QLineEdit {
padding: 0px; padding: 0px;
show-decoration-selected: 1; show-decoration-selected: 1;
} }
/* Checked item in dropdowns have way too much height... /* Checked item in dropdowns have way too much height...
see #6281 and https://github.com/ColinDuquesnoy/QDarkStyleSheet/issues/200 see #6281 and https://github.com/ColinDuquesnoy/QDarkStyleSheet/issues/200
*/ */
QComboBox::item:checked { QComboBox::item:checked {
font-weight: bold; font-weight: bold;
max-height: 30px; max-height: 30px;
} }
''' '''
CUSTOM_PATCH_FOR_DEFAULT_THEME_MACOS = '''
/* On macOS, main window status bar icons have ugly frame (see #6300) */
StatusBarButton {
background-color: transparent;
border: 1px solid transparent;
border-radius: 4px;
margin: 0px;
padding: 2px;
}
StatusBarButton:checked {
background-color: transparent;
border: 1px solid #1464A0;
}
StatusBarButton:checked:disabled {
border: 1px solid #14506E;
}
StatusBarButton:pressed {
margin: 1px;
background-color: transparent;
border: 1px solid #1464A0;
}
StatusBarButton:disabled {
border: none;
}
StatusBarButton:hover {
border: 1px solid #148CD2;
}
'''
def patch_qt_stylesheet(use_dark_theme: bool) -> None:
custom_patch = ""
if use_dark_theme:
custom_patch = CUSTOM_PATCH_FOR_DARK_THEME
else: # default theme (typically light)
if sys.platform == 'darwin':
custom_patch = CUSTOM_PATCH_FOR_DEFAULT_THEME_MACOS
app = QtWidgets.QApplication.instance()
style_sheet = app.styleSheet() + custom_patch
app.setStyleSheet(style_sheet) app.setStyleSheet(style_sheet)

Loading…
Cancel
Save