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. 80
      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('')

80
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.
""" """
import sys
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
CUSTOM_PATCH_FOR_DARK_THEME = '''
/* PayToEdit text was being clipped */
QAbstractScrollArea {
padding: 0px;
}
/* In History tab, labels while edited were being clipped (Windows) */
QAbstractItemView QLineEdit {
padding: 0px;
show-decoration-selected: 1;
}
/* Checked item in dropdowns have way too much height...
see #6281 and https://github.com/ColinDuquesnoy/QDarkStyleSheet/issues/200
*/
QComboBox::item:checked {
font-weight: bold;
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: def patch_qt_stylesheet(use_dark_theme: bool) -> None:
if not use_dark_theme: custom_patch = ""
return 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() app = QtWidgets.QApplication.instance()
style_sheet = app.styleSheet() + custom_patch
style_sheet = app.styleSheet()
style_sheet = style_sheet + '''
/* PayToEdit text was being clipped */
QAbstractScrollArea {
padding: 0px;
}
/* In History tab, labels while edited were being clipped (Windows) */
QAbstractItemView QLineEdit {
padding: 0px;
show-decoration-selected: 1;
}
/* Checked item in dropdowns have way too much height...
see #6281 and https://github.com/ColinDuquesnoy/QDarkStyleSheet/issues/200
*/
QComboBox::item:checked {
font-weight: bold;
max-height: 30px;
}
'''
app.setStyleSheet(style_sheet) app.setStyleSheet(style_sheet)

Loading…
Cancel
Save