summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-08-26 19:56:54 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-08-27 13:45:37 +0000
commit626418ad136e58af01599c17ef999f367f5c0619 (patch)
tree6008edbcd840d6ae48dd88d2e265bd0dbb981d95 /src
parent25b257d5fc0e15294329b0127ec53cc389257258 (diff)
QToolButton: reimplement the fix for QTBUG-95255
The code in 188d739400e10fc8571bbf2ec86d5cd338b04a5d uses a connect() to a lambda, passing UniqueConnection to avoid establishing the connection more than once. The problem is that UniqueConnection does not work with lambdas; it works only with "regular" PMFs to QObject subclasses. Re-do the same fix, but without a connection: use the checkStateSet() virtual from the base class that will notify us if setChecked() is being called on the tool button, and from there synchronize the state of the default action. Change-Id: Id512812c562cd6d20bc1a489753b33c269919d32 Fixes: QTBUG-95255 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit c9830c2fb902f26dc8b2df61dfadc2d7a7d2b30e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/widgets/qtoolbutton.cpp16
-rw-r--r--src/widgets/widgets/qtoolbutton.h1
2 files changed, 10 insertions, 7 deletions
diff --git a/src/widgets/widgets/qtoolbutton.cpp b/src/widgets/widgets/qtoolbutton.cpp
index 81b2998849..2c7f973947 100644
--- a/src/widgets/widgets/qtoolbutton.cpp
+++ b/src/widgets/widgets/qtoolbutton.cpp
@@ -963,12 +963,6 @@ void QToolButton::setDefaultAction(QAction *action)
}
#endif
setCheckable(action->isCheckable());
- if (action->isCheckable()) {
- connect(this, &QAbstractButton::toggled, this, [this](bool checked) {
- if (defaultAction())
- defaultAction()->setChecked(checked);
- }, Qt::UniqueConnection);
- }
setChecked(action->isChecked());
setEnabled(action->isEnabled());
if (action->d_func()->fontSet)
@@ -987,7 +981,15 @@ QAction *QToolButton::defaultAction() const
return d->defaultAction;
}
-
+/*!
+ \reimp
+ */
+void QToolButton::checkStateSet()
+{
+ Q_D(QToolButton);
+ if (d->defaultAction && d->defaultAction->isCheckable())
+ d->defaultAction->setChecked(isChecked());
+}
/*!
\reimp
diff --git a/src/widgets/widgets/qtoolbutton.h b/src/widgets/widgets/qtoolbutton.h
index 96702c145f..062eeea708 100644
--- a/src/widgets/widgets/qtoolbutton.h
+++ b/src/widgets/widgets/qtoolbutton.h
@@ -118,6 +118,7 @@ protected:
void changeEvent(QEvent *) override;
bool hitButton(const QPoint &pos) const override;
+ void checkStateSet() override;
void nextCheckState() override;
virtual void initStyleOption(QStyleOptionToolButton *option) const;