QColorDialog: Stop color picking when application is deactivated

Fixes: QTBUG-134143
Pick-to: 6.10
Change-Id: Ibfeff4f861ac5c63f4bdd85db40b25eee51c4d31
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Friedemann Kleint 2025-06-04 14:01:02 +02:00
parent 4e57583f33
commit 38ce4ad2f8

View File

@ -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();