Skip to content

Commit 22e0114

Browse files
committed
qt: Choose monospaced font in C++ code rather in *.ui file
Setting the "Monospace" font family in a `*.ui` file does not work on macOS, at least on Big Sur with Qt 5.15 (neither via the "font" property nor via the "styleSheet" property). Qt chooses the ".AppleSystemUIFont" instead of ".AppleSystemUIFontMonospaced". This change makes macOS choose the correct monospaced font.
1 parent 623de12 commit 22e0114

File tree

3 files changed

+17
-56
lines changed

3 files changed

+17
-56
lines changed

src/qt/forms/overviewpage.ui

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@
116116
</property>
117117
<item row="2" column="2">
118118
<widget class="QLabel" name="labelWatchPending">
119-
<property name="font">
120-
<font>
121-
<family>Monospace</family>
122-
<weight>75</weight>
123-
<bold>true</bold>
124-
</font>
125-
</property>
126119
<property name="cursor">
127120
<cursorShape>IBeamCursor</cursorShape>
128121
</property>
@@ -142,13 +135,6 @@
142135
</item>
143136
<item row="2" column="1">
144137
<widget class="QLabel" name="labelUnconfirmed">
145-
<property name="font">
146-
<font>
147-
<family>Monospace</family>
148-
<weight>75</weight>
149-
<bold>true</bold>
150-
</font>
151-
</property>
152138
<property name="cursor">
153139
<cursorShape>IBeamCursor</cursorShape>
154140
</property>
@@ -168,13 +154,6 @@
168154
</item>
169155
<item row="3" column="2">
170156
<widget class="QLabel" name="labelWatchImmature">
171-
<property name="font">
172-
<font>
173-
<family>Monospace</family>
174-
<weight>75</weight>
175-
<bold>true</bold>
176-
</font>
177-
</property>
178157
<property name="cursor">
179158
<cursorShape>IBeamCursor</cursorShape>
180159
</property>
@@ -227,13 +206,6 @@
227206
</item>
228207
<item row="3" column="1">
229208
<widget class="QLabel" name="labelImmature">
230-
<property name="font">
231-
<font>
232-
<family>Monospace</family>
233-
<weight>75</weight>
234-
<bold>true</bold>
235-
</font>
236-
</property>
237209
<property name="cursor">
238210
<cursorShape>IBeamCursor</cursorShape>
239211
</property>
@@ -273,13 +245,6 @@
273245
</item>
274246
<item row="5" column="1">
275247
<widget class="QLabel" name="labelTotal">
276-
<property name="font">
277-
<font>
278-
<family>Monospace</family>
279-
<weight>75</weight>
280-
<bold>true</bold>
281-
</font>
282-
</property>
283248
<property name="cursor">
284249
<cursorShape>IBeamCursor</cursorShape>
285250
</property>
@@ -299,13 +264,6 @@
299264
</item>
300265
<item row="5" column="2">
301266
<widget class="QLabel" name="labelWatchTotal">
302-
<property name="font">
303-
<font>
304-
<family>Monospace</family>
305-
<weight>75</weight>
306-
<bold>true</bold>
307-
</font>
308-
</property>
309267
<property name="cursor">
310268
<cursorShape>IBeamCursor</cursorShape>
311269
</property>
@@ -342,13 +300,6 @@
342300
</item>
343301
<item row="1" column="1">
344302
<widget class="QLabel" name="labelBalance">
345-
<property name="font">
346-
<font>
347-
<family>Monospace</family>
348-
<weight>75</weight>
349-
<bold>true</bold>
350-
</font>
351-
</property>
352303
<property name="cursor">
353304
<cursorShape>IBeamCursor</cursorShape>
354305
</property>
@@ -368,13 +319,6 @@
368319
</item>
369320
<item row="1" column="2">
370321
<widget class="QLabel" name="labelWatchAvailable">
371-
<property name="font">
372-
<font>
373-
<family>Monospace</family>
374-
<weight>75</weight>
375-
<bold>true</bold>
376-
</font>
377-
</property>
378322
<property name="cursor">
379323
<cursorShape>IBeamCursor</cursorShape>
380324
</property>

src/qt/overviewpage.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ void OverviewPage::setClientModel(ClientModel *model)
257257
// Show warning, for example if this is a prerelease version
258258
connect(model, &ClientModel::alertsChanged, this, &OverviewPage::updateAlerts);
259259
updateAlerts(model->getStatusBarWarnings());
260+
261+
setMonospacedFont(false);
260262
}
261263
}
262264

@@ -321,3 +323,17 @@ void OverviewPage::showOutOfSyncWarning(bool fShow)
321323
ui->labelWalletStatus->setVisible(fShow);
322324
ui->labelTransactionsStatus->setVisible(fShow);
323325
}
326+
327+
void OverviewPage::setMonospacedFont(bool use_embedded_font)
328+
{
329+
QFont f = GUIUtil::fixedPitchFont(use_embedded_font);
330+
f.setWeight(QFont::Bold);
331+
ui->labelBalance->setFont(f);
332+
ui->labelUnconfirmed->setFont(f);
333+
ui->labelImmature->setFont(f);
334+
ui->labelTotal->setFont(f);
335+
ui->labelWatchAvailable->setFont(f);
336+
ui->labelWatchPending->setFont(f);
337+
ui->labelWatchImmature->setFont(f);
338+
ui->labelWatchTotal->setFont(f);
339+
}

src/qt/overviewpage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private Q_SLOTS:
6161
void updateAlerts(const QString &warnings);
6262
void updateWatchOnlyLabels(bool showWatchOnly);
6363
void handleOutOfSyncWarningClicks();
64+
void setMonospacedFont(bool use_embedded_font);
6465
};
6566

6667
#endif // BITCOIN_QT_OVERVIEWPAGE_H

0 commit comments

Comments
 (0)