1
0

Merge pull request #6300 from SomberNight/202006_qt_statusbarbutton

qt StatusBarButton: use QToolButton instead of QPushButton
This commit is contained in:
ghost43
2020-12-09 12:42:23 +00:00
committed by GitHub
3 changed files with 71 additions and 29 deletions

View File

@@ -46,7 +46,7 @@ from PyQt5.QtWidgets import (QMessageBox, QComboBox, QSystemTrayIcon, QTabWidget
QHBoxLayout, QPushButton, QScrollArea, QTextEdit,
QShortcut, QMainWindow, QCompleter, QInputDialog,
QWidget, QSizePolicy, QStatusBar, QToolTip, QDialog,
QMenu, QAction, QStackedWidget)
QMenu, QAction, QStackedWidget, QToolButton)
import electrum
from electrum import (keystore, ecc, constants, util, bitcoin, commands,
@@ -104,11 +104,16 @@ if TYPE_CHECKING:
LN_NUM_PAYMENT_ATTEMPTS = 10
class StatusBarButton(QPushButton):
class StatusBarButton(QToolButton):
# note: this class has a custom stylesheet applied in stylesheet_patcher.py
def __init__(self, icon, tooltip, func):
QPushButton.__init__(self, icon, '')
QToolButton.__init__(self)
self.setText('')
self.setIcon(icon)
self.setToolTip(tooltip)
self.setFlat(True)
self.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
self.setAutoRaise(True)
self.setMaximumWidth(25)
self.clicked.connect(self.onPress)
self.func = func
@@ -2239,7 +2244,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
self.lightning_button.setText('')
self.lightning_button.setToolTip(_("The Lightning Network graph is fully synced."))
else:
self.lightning_button.setMaximumWidth(25 + 4 * char_width_in_lineedit())
self.lightning_button.setMaximumWidth(25 + 5 * char_width_in_lineedit())
self.lightning_button.setText(progress_str)
self.lightning_button.setToolTip(_("The Lightning Network graph is syncing...\n"
"Payments are more likely to succeed with a more complete graph."))

View File

@@ -2,32 +2,68 @@
It reads the current stylesheet, appends our modifications and sets the new stylesheet.
"""
import sys
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:
if not use_dark_theme:
return
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()
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;
}
'''
style_sheet = app.styleSheet() + custom_patch
app.setStyleSheet(style_sheet)

View File

@@ -126,9 +126,10 @@ class HelpLabel(QLabel):
return QLabel.leaveEvent(self, event)
class HelpButton(QPushButton):
class HelpButton(QToolButton):
def __init__(self, text):
QPushButton.__init__(self, '?')
QToolButton.__init__(self)
self.setText('?')
self.help_text = text
self.setFocusPolicy(Qt.NoFocus)
self.setFixedWidth(round(2.2 * char_width_in_lineedit()))