diff --git a/src/xenia/ui/qt/widgets/push_button.cc b/src/xenia/ui/qt/widgets/push_button.cc index 3261ce642..9630635f8 100644 --- a/src/xenia/ui/qt/widgets/push_button.cc +++ b/src/xenia/ui/qt/widgets/push_button.cc @@ -20,6 +20,31 @@ XPushButton::XPushButton(const QIcon& icon, const QString& text, Build(); } +void XPushButton::SetIconFromGlyph(QChar glyph, QColor color, int size) { + auto glyph_font = QFont("Segoe MDL2 Assets", size); + // Measure the Glyph + QFontMetrics measure(glyph_font); + QRect icon_rect = measure.boundingRect(glyph); + double max = qMax(icon_rect.width(), icon_rect.height()); + + // Create the Pixmap + // boundingRect can be inaccurate so add a 4px padding to be safe + QPixmap pixmap(max + 4, max + 4); + pixmap.fill(Qt::transparent); + + // Paint the Glyph + QPainter painter(&pixmap); + painter.setFont(glyph_font); + painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); + painter.setPen(QPen(color)); + + painter.drawText(pixmap.rect(), Qt::AlignVCenter, glyph); + + painter.end(); + + this->setIcon(pixmap); +} + void XPushButton::Build() { setFlat(true); setCursor(Qt::PointingHandCursor); diff --git a/src/xenia/ui/qt/widgets/push_button.h b/src/xenia/ui/qt/widgets/push_button.h index 02bad5db7..991ef4baf 100644 --- a/src/xenia/ui/qt/widgets/push_button.h +++ b/src/xenia/ui/qt/widgets/push_button.h @@ -16,6 +16,8 @@ class XPushButton : public Themeable { XPushButton(const QIcon& icon, const QString& text, QWidget* parent = nullptr); + void SetIconFromGlyph(QChar glyph, QColor color = Qt::white, int size = 64); + private: void Build(); };