summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Spoerl <[email protected]>2025-06-05 18:58:16 +0200
committerAxel Spoerl <[email protected]>2025-06-06 06:26:13 +0200
commit839d569dc27cfa5188db477893899d849ac26ea5 (patch)
treed68bf98e13357f21998f1475e42b7f0e786fabe5
parent2e0dc22bdb46f94a516e834ad4fda2b93aada352 (diff)
QCommandLinkButton: Don't reset icon on change to QStyleSheetStyleHEADdev
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 <[email protected]>
-rw-r--r--src/widgets/widgets/qcommandlinkbutton.cpp16
1 files 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 <qmath.h>
#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<QStyleSheetStyle *>(style())) {
+ QStyleOptionButton opt;
+ initStyleOption(&opt);
+ setIcon(style()->standardIcon(QStyle::SP_CommandLink, &opt, this));
+ }
}
return QPushButton::event(e);