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.
pull/826/head
Hennadii Stepanov 4 years ago
parent 623de12d04
commit 22e0114d05
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F

@ -116,13 +116,6 @@
</property> </property>
<item row="2" column="2"> <item row="2" column="2">
<widget class="QLabel" name="labelWatchPending"> <widget class="QLabel" name="labelWatchPending">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="cursor"> <property name="cursor">
<cursorShape>IBeamCursor</cursorShape> <cursorShape>IBeamCursor</cursorShape>
</property> </property>
@ -142,13 +135,6 @@
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QLabel" name="labelUnconfirmed"> <widget class="QLabel" name="labelUnconfirmed">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="cursor"> <property name="cursor">
<cursorShape>IBeamCursor</cursorShape> <cursorShape>IBeamCursor</cursorShape>
</property> </property>
@ -168,13 +154,6 @@
</item> </item>
<item row="3" column="2"> <item row="3" column="2">
<widget class="QLabel" name="labelWatchImmature"> <widget class="QLabel" name="labelWatchImmature">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="cursor"> <property name="cursor">
<cursorShape>IBeamCursor</cursorShape> <cursorShape>IBeamCursor</cursorShape>
</property> </property>
@ -227,13 +206,6 @@
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QLabel" name="labelImmature"> <widget class="QLabel" name="labelImmature">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="cursor"> <property name="cursor">
<cursorShape>IBeamCursor</cursorShape> <cursorShape>IBeamCursor</cursorShape>
</property> </property>
@ -273,13 +245,6 @@
</item> </item>
<item row="5" column="1"> <item row="5" column="1">
<widget class="QLabel" name="labelTotal"> <widget class="QLabel" name="labelTotal">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="cursor"> <property name="cursor">
<cursorShape>IBeamCursor</cursorShape> <cursorShape>IBeamCursor</cursorShape>
</property> </property>
@ -299,13 +264,6 @@
</item> </item>
<item row="5" column="2"> <item row="5" column="2">
<widget class="QLabel" name="labelWatchTotal"> <widget class="QLabel" name="labelWatchTotal">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="cursor"> <property name="cursor">
<cursorShape>IBeamCursor</cursorShape> <cursorShape>IBeamCursor</cursorShape>
</property> </property>
@ -342,13 +300,6 @@
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLabel" name="labelBalance"> <widget class="QLabel" name="labelBalance">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="cursor"> <property name="cursor">
<cursorShape>IBeamCursor</cursorShape> <cursorShape>IBeamCursor</cursorShape>
</property> </property>
@ -368,13 +319,6 @@
</item> </item>
<item row="1" column="2"> <item row="1" column="2">
<widget class="QLabel" name="labelWatchAvailable"> <widget class="QLabel" name="labelWatchAvailable">
<property name="font">
<font>
<family>Monospace</family>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="cursor"> <property name="cursor">
<cursorShape>IBeamCursor</cursorShape> <cursorShape>IBeamCursor</cursorShape>
</property> </property>

@ -257,6 +257,8 @@ void OverviewPage::setClientModel(ClientModel *model)
// Show warning, for example if this is a prerelease version // Show warning, for example if this is a prerelease version
connect(model, &ClientModel::alertsChanged, this, &OverviewPage::updateAlerts); connect(model, &ClientModel::alertsChanged, this, &OverviewPage::updateAlerts);
updateAlerts(model->getStatusBarWarnings()); updateAlerts(model->getStatusBarWarnings());
setMonospacedFont(false);
} }
} }
@ -321,3 +323,17 @@ void OverviewPage::showOutOfSyncWarning(bool fShow)
ui->labelWalletStatus->setVisible(fShow); ui->labelWalletStatus->setVisible(fShow);
ui->labelTransactionsStatus->setVisible(fShow); ui->labelTransactionsStatus->setVisible(fShow);
} }
void OverviewPage::setMonospacedFont(bool use_embedded_font)
{
QFont f = GUIUtil::fixedPitchFont(use_embedded_font);
f.setWeight(QFont::Bold);
ui->labelBalance->setFont(f);
ui->labelUnconfirmed->setFont(f);
ui->labelImmature->setFont(f);
ui->labelTotal->setFont(f);
ui->labelWatchAvailable->setFont(f);
ui->labelWatchPending->setFont(f);
ui->labelWatchImmature->setFont(f);
ui->labelWatchTotal->setFont(f);
}

@ -61,6 +61,7 @@ private Q_SLOTS:
void updateAlerts(const QString &warnings); void updateAlerts(const QString &warnings);
void updateWatchOnlyLabels(bool showWatchOnly); void updateWatchOnlyLabels(bool showWatchOnly);
void handleOutOfSyncWarningClicks(); void handleOutOfSyncWarningClicks();
void setMonospacedFont(bool use_embedded_font);
}; };
#endif // BITCOIN_QT_OVERVIEWPAGE_H #endif // BITCOIN_QT_OVERVIEWPAGE_H

Loading…
Cancel
Save