From 9b3756e591eea4028dc845557e85f674de3d2c69 Mon Sep 17 00:00:00 2001 From: BruebachL <44814898+BruebachL@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:19:12 +0200 Subject: [PATCH] Don't setText() in paintEvent() which causes infinite recursion on MacOs. Use a styleOption to paint base class directly instead. (#6146) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Took 18 minutes Took 5 seconds Took 19 seconds Co-authored-by: Lukas BrĂ¼bach --- .../ui/widgets/general/home_styled_button.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cockatrice/src/client/ui/widgets/general/home_styled_button.cpp b/cockatrice/src/client/ui/widgets/general/home_styled_button.cpp index 4a0b0e7d6..66bb0417b 100644 --- a/cockatrice/src/client/ui/widgets/general/home_styled_button.cpp +++ b/cockatrice/src/client/ui/widgets/general/home_styled_button.cpp @@ -3,6 +3,7 @@ #include #include #include +#include HomeStyledButton::HomeStyledButton(const QString &text, QPair _gradientColors, QWidget *parent) : QPushButton(text, parent), gradientColors(_gradientColors) @@ -75,14 +76,15 @@ QString HomeStyledButton::generateButtonStylesheet(const QPair & void HomeStyledButton::paintEvent(QPaintEvent *event) { - QString originalText = text(); - setText(""); // Prevent QPushButton from drawing the text - - QPushButton::paintEvent(event); // Draw background, borders, etc. - - setText(originalText); // Restore text for internal logic + Q_UNUSED(event); // Event is just used for update clipping, we redraw the whole widget. + QStyleOptionButton opt; + initStyleOption(&opt); + opt.text.clear(); // prevent style from drawing text QPainter painter(this); + style()->drawControl(QStyle::CE_PushButton, &opt, &painter, this); + + // Draw white text with a black outline painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::TextAntialiasing); @@ -91,11 +93,11 @@ void HomeStyledButton::paintEvent(QPaintEvent *event) painter.setFont(font); QFontMetrics fm(font); - QSize textSize = fm.size(Qt::TextSingleLine, originalText); + QSize textSize = fm.size(Qt::TextSingleLine, this->text()); QPointF center((width() - textSize.width()) / 2.0, (height() + textSize.height() / 2.0) / 2.0); QPainterPath path; - path.addText(center, font, originalText); + path.addText(center, font, this->text()); painter.setPen(QPen(Qt::black, 2.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush(Qt::white);