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

@ -257,6 +257,8 @@ void OverviewPage::setClientModel(ClientModel *model)
// Show warning, for example if this is a prerelease version
connect(model, &ClientModel::alertsChanged, this, &OverviewPage::updateAlerts);
updateAlerts(model->getStatusBarWarnings());
setMonospacedFont(false);
}
}
@ -321,3 +323,17 @@ void OverviewPage::showOutOfSyncWarning(bool fShow)
ui->labelWalletStatus->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 updateWatchOnlyLabels(bool showWatchOnly);
void handleOutOfSyncWarningClicks();
void setMonospacedFont(bool use_embedded_font);
};
#endif // BITCOIN_QT_OVERVIEWPAGE_H

Loading…
Cancel
Save