From 839d569dc27cfa5188db477893899d849ac26ea5 Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Thu, 5 Jun 2025 18:58:16 +0200 Subject: [PATCH] QCommandLinkButton: Don't reset icon on change to QStyleSheetStyle d4c518b210ad56cb51c17e6e1b4a81b0deb7253c has implemented a reset of the icon on a style change. This has caused a regression, because it overrode an icon set by a style sheet. Do not reset the icon if the new style is a QStyleSheetStyle. Amdends d4c518b210ad56cb51c17e6e1b4a81b0deb7253c. Fixes: QTBUG-137011 Pick-to: 6.10 6.9 6.8 Change-Id: Ib77faa03c867b2660a45bdc3ab94e7d739eed4f8 Reviewed-by: Christian Ehrlicher --- src/widgets/widgets/qcommandlinkbutton.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/widgets/widgets/qcommandlinkbutton.cpp b/src/widgets/widgets/qcommandlinkbutton.cpp index 815e00e5498..1fa84392574 100644 --- a/src/widgets/widgets/qcommandlinkbutton.cpp +++ b/src/widgets/widgets/qcommandlinkbutton.cpp @@ -11,6 +11,7 @@ #include #include "private/qpushbutton_p.h" +#include "private/qstylesheetstyle_p.h" QT_BEGIN_NAMESPACE @@ -277,9 +278,18 @@ QCommandLinkButton::~QCommandLinkButton() bool QCommandLinkButton::event(QEvent *e) { if (e->type() == QEvent::StyleChange) { - QStyleOptionButton opt; - initStyleOption(&opt); - setIcon(style()->standardIcon(QStyle::SP_CommandLink, &opt, this)); + // If the new style is a QStyleSheetStyle, don't reset the icon, because: + // - either it has been explicitly set, in which case we want to keep it. + // - or it has been initialised by the previous style, which is now the base style, + // in which case we want to keep it as well. + // - or it has been set in the style sheet, in which case we don't want to override it here. + // When a style sheet with an icon is replaced by one without an icon, the old icon + // will be reset, when baseStyle()->repolish() is called. + if (!qobject_cast(style())) { + QStyleOptionButton opt; + initStyleOption(&opt); + setIcon(style()->standardIcon(QStyle::SP_CommandLink, &opt, this)); + } } return QPushButton::event(e);