Skip to content

Commit d05f1b2

Browse files
committed
qt: Make UnitDisplayStatusBarControl aware of runtime palette change
This change fixes the GUI when changing appearance on macOS.
1 parent 6b2ce65 commit d05f1b2

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/qt/bitcoingui.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,9 +1450,10 @@ bool BitcoinGUI::isPrivacyModeActivated() const
14501450
return m_mask_values_action->isChecked();
14511451
}
14521452

1453-
UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *platformStyle) :
1454-
optionsModel(nullptr),
1455-
menu(nullptr)
1453+
UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *platformStyle)
1454+
: optionsModel(nullptr),
1455+
menu(nullptr),
1456+
m_platform_style{platformStyle}
14561457
{
14571458
createContextMenu();
14581459
setToolTip(tr("Unit to show amounts in. Click to select another unit."));
@@ -1465,7 +1466,7 @@ UnitDisplayStatusBarControl::UnitDisplayStatusBarControl(const PlatformStyle *pl
14651466
}
14661467
setMinimumSize(max_width, 0);
14671468
setAlignment(Qt::AlignRight | Qt::AlignVCenter);
1468-
setStyleSheet(QString("QLabel { color : %1 }").arg(platformStyle->SingleColor().name()));
1469+
setStyleSheet(QString("QLabel { color : %1 }").arg(m_platform_style->SingleColor().name()));
14691470
}
14701471

14711472
/** So that it responds to button clicks */
@@ -1474,6 +1475,18 @@ void UnitDisplayStatusBarControl::mousePressEvent(QMouseEvent *event)
14741475
onDisplayUnitsClicked(event->pos());
14751476
}
14761477

1478+
void UnitDisplayStatusBarControl::changeEvent(QEvent* e)
1479+
{
1480+
#ifdef Q_OS_MACOS
1481+
if (e->type() == QEvent::PaletteChange) {
1482+
QString style = QString("QLabel { color : %1 }").arg(m_platform_style->SingleColor().name());
1483+
if (style != styleSheet()) {
1484+
setStyleSheet(style);
1485+
}
1486+
}
1487+
#endif
1488+
}
1489+
14771490
/** Creates context menu, its actions, and wires up all the relevant signals for mouse events. */
14781491
void UnitDisplayStatusBarControl::createContextMenu()
14791492
{

src/qt/bitcoingui.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,12 @@ class UnitDisplayStatusBarControl : public QLabel
334334
protected:
335335
/** So that it responds to left-button clicks */
336336
void mousePressEvent(QMouseEvent *event) override;
337+
void changeEvent(QEvent* e) override;
337338

338339
private:
339340
OptionsModel *optionsModel;
340341
QMenu* menu;
342+
const PlatformStyle* m_platform_style;
341343

342344
/** Shows context menu with Display Unit options by the mouse coordinates */
343345
void onDisplayUnitsClicked(const QPoint& point);

0 commit comments

Comments
 (0)