From 38ce4ad2f863fbd312334e239c0362ce3657830c Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 4 Jun 2025 14:01:02 +0200 Subject: [PATCH] QColorDialog: Stop color picking when application is deactivated Fixes: QTBUG-134143 Pick-to: 6.10 Change-Id: Ibfeff4f861ac5c63f4bdd85db40b25eee51c4d31 Reviewed-by: Axel Spoerl --- src/widgets/dialogs/qcolordialog.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index 6c2ca12825f..bb9202f8dec 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -500,6 +500,12 @@ public: return false; } + void applicationStateChanged(Qt::ApplicationState state) + { + if (state != Qt::ApplicationActive) + m_dp->releaseColorPicking(); + } + private: QColorDialogPrivate *m_dp; }; @@ -1625,6 +1631,8 @@ void QColorDialogPrivate::pickScreenColor() if (!colorPickingEventFilter) colorPickingEventFilter = new QColorPickingEventFilter(this, q); q->installEventFilter(colorPickingEventFilter); + QObject::connect(qApp, &QGuiApplication::applicationStateChanged, + colorPickingEventFilter, &QColorPickingEventFilter::applicationStateChanged); // If user pushes Escape, the last color before picking will be restored. beforeScreenColorPicking = cs->currentColor(); #ifndef QT_NO_CURSOR @@ -1671,6 +1679,8 @@ void QColorDialogPrivate::releaseColorPicking() Q_Q(QColorDialog); cp->setCrossVisible(true); q->removeEventFilter(colorPickingEventFilter); + QObject::disconnect(qApp, &QGuiApplication::applicationStateChanged, + colorPickingEventFilter, &QColorPickingEventFilter::applicationStateChanged); q->releaseMouse(); #ifdef Q_OS_WIN32 updateTimer->stop();