Skip to content

Commit 800cf66

Browse files
committed
qt: recognize system monospace font as non-selectable font
1 parent 85b49b9 commit 800cf66

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

src/qt/guiutil.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,6 @@ QString dateTimeStr(qint64 nTime)
230230
return dateTimeStr(QDateTime::fromSecsSinceEpoch((qint32)nTime));
231231
}
232232

233-
QFont fixedPitchFont(bool use_embedded_font)
234-
{
235-
if (use_embedded_font) {
236-
return {"Roboto Mono"};
237-
}
238-
return QFontDatabase::systemFont(QFontDatabase::FixedFont);
239-
}
240-
241233
// Just some dummy data to generate a convincing random-looking (but consistent) address
242234
static const uint8_t dummydata[] = {0xeb,0x15,0x23,0x1d,0xfc,0xeb,0x60,0x92,0x58,0x86,0xb6,0x7d,0x06,0x52,0x99,0x92,0x59,0x15,0xae,0xb1,0x72,0xc0,0x66,0x47};
243235

src/qt/guiutil.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ namespace GUIUtil
125125
QString dateTimeStr(const QDateTime &datetime);
126126
QString dateTimeStr(qint64 nTime);
127127

128-
// Return a monospace font
129-
QFont fixedPitchFont(bool use_embedded_font = false);
130-
131128
// Set up widget for address
132129
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent, bool fAllowURI = false);
133130

src/qt/guiutil_font.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ namespace GUIUtil {
120120
std::vector<std::pair<QString, /*selectable=*/bool>> g_fonts_known{
121121
{MONTSERRAT_FONT_STR.toUtf8(), true},
122122
{OS_FONT_STR.toUtf8(), true},
123+
{OS_MONO_FONT_STR.toUtf8(), false},
123124
{ROBOTO_MONO_FONT_STR.toUtf8(), false},
124125
};
125126

@@ -474,11 +475,13 @@ QFont getFont(const QString& font_name, const FontAttrib& font_attrib)
474475
#endif // Q_OS_MACOS
475476
} else if (font_name == OS_FONT_STR) {
476477
font.setFamily(g_default_font->family());
478+
} else if (font_name == OS_MONO_FONT_STR) {
479+
font.setFamily(QFontDatabase::systemFont(QFontDatabase::FixedFont).family());
477480
} else {
478481
font.setFamily(font_name);
479482
}
480483

481-
if (font_name == ROBOTO_MONO_FONT_STR) {
484+
if (font_name == ROBOTO_MONO_FONT_STR || font_name == OS_MONO_FONT_STR) {
482485
font.setStyleHint(QFont::Monospace);
483486
}
484487

@@ -544,4 +547,12 @@ int FontRegistry::WeightToIdx(const QFont::Weight& weight) const
544547
}
545548
return -1;
546549
}
550+
551+
QFont fixedPitchFont(bool use_embedded_font)
552+
{
553+
return getFont({
554+
use_embedded_font ? ROBOTO_MONO_FONT_STR.toUtf8() : OS_MONO_FONT_STR.toUtf8(),
555+
g_font_registry.GetWeightNormal()
556+
});
557+
}
547558
} // namespace GUIUtil

src/qt/guiutil_font.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace GUIUtil {
1919
// TODO: Switch to QUtf8StringView when we switch to Qt 6
2020
constexpr QStringView MONTSERRAT_FONT_STR{u"Montserrat"};
2121
constexpr QStringView OS_FONT_STR{u"SystemDefault"};
22+
constexpr QStringView OS_MONO_FONT_STR{u"SystemMonospace"};
2223
constexpr QStringView ROBOTO_MONO_FONT_STR{u"Roboto Mono"};
2324

2425
enum class FontWeight : uint8_t {
@@ -160,6 +161,9 @@ QFont getFontNormal();
160161

161162
/** Get the default bold QFont */
162163
QFont getFontBold();
164+
165+
/** (Bitcoin) Return a monospace font */
166+
QFont fixedPitchFont(bool use_embedded_font = false);
163167
} // namespace GUIUtil
164168

165169
#endif // BITCOIN_QT_GUIUTIL_FONT_H

0 commit comments

Comments
 (0)