From a00fb1c9559180bfbcd68b164082ccf555001b74 Mon Sep 17 00:00:00 2001 From: Doris Verria Date: Thu, 10 Dec 2020 01:42:22 +0100 Subject: [PATCH] Override initStyleOption() for QCommandLinkButton In QPushButton::initStyleOption() there is no style option feature set to distinguish QCommandLinkButtons. The QStyleOptionButton::CommandLink Button feature is only set during the paintEvent, but in some cases we need to check for this feature before painting. To fix, override initStyleOption for QCommandLinkButton and set the fea ture there. Change-Id: I8831a6be7da642dcf8830812d99681213e7515dc Reviewed-by: Volker Hilsheimer (cherry picked from commit d3ee976acab59019fdd781691f29e6f12e4dedc8) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/widgets/qcommandlinkbutton.cpp | 6 ++++++ src/widgets/widgets/qcommandlinkbutton.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/widgets/widgets/qcommandlinkbutton.cpp b/src/widgets/widgets/qcommandlinkbutton.cpp index e9462ed229c..4f0de092be1 100644 --- a/src/widgets/widgets/qcommandlinkbutton.cpp +++ b/src/widgets/widgets/qcommandlinkbutton.cpp @@ -264,6 +264,12 @@ QSize QCommandLinkButton::minimumSizeHint() const return size; } +void QCommandLinkButton::initStyleOption(QStyleOptionButton *option) const +{ + QPushButton::initStyleOption(option); + option->features |= QStyleOptionButton::CommandLinkButton; +} + /*! Constructs a command link with no text and a \a parent. */ diff --git a/src/widgets/widgets/qcommandlinkbutton.h b/src/widgets/widgets/qcommandlinkbutton.h index c48522ee620..2a1ae058073 100644 --- a/src/widgets/widgets/qcommandlinkbutton.h +++ b/src/widgets/widgets/qcommandlinkbutton.h @@ -69,6 +69,7 @@ public: QSize sizeHint() const override; int heightForWidth(int) const override; QSize minimumSizeHint() const override; + void initStyleOption(QStyleOptionButton *option) const override; protected: bool event(QEvent *e) override;