From aa0f395fd1ba874a908c040229d43bde7c9b650f Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Thu, 27 Jul 2023 12:01:34 +0200 Subject: [PATCH] QColorDialog: Ignore mouse move events when no mouse button is pressed mouseMoveEvent overrides in QColorLuminancePicker and QColorPicker have triggered value changes unconditionally. This happened under the assumption that the widget attribute WA_Hover is not set (which is the default behavior). In that case, mouseMoveEvents are only delivered if a button is pressed. If WA_Hover is set - e.g. by applying a style sheet - mouseMoveEvents get delivered also when no button is pressed. This leads to faulty behavior: The color and the luminance change, whenever the mouse is moved into the respective widget. Color/luminance are changed to the value representing the edge on which the mouse has left the area. This patch changes both mouseMoveEvent overrides. They return early to avoid hovering changing the colors of the luminance/color picker, but ignore() the event in case anything behind the picker needs hover. Since this is a purely graphical effect, an autotest was not added. Fixes: QTBUG-115516 Change-Id: I000d113a1c81c46799cbb5197bf9acb3849e7d3b Reviewed-by: Shawn Rutledge (cherry picked from commit a2ec43b8ebcbf8462928800a7db4f6af7e482b18) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/dialogs/qcolordialog.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index 4ab9b88c8fd..bb4f75c281b 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -780,6 +780,10 @@ QColorLuminancePicker::~QColorLuminancePicker() void QColorLuminancePicker::mouseMoveEvent(QMouseEvent *m) { + if (m->buttons() == Qt::NoButton) { + m->ignore(); + return; + } setVal(y2val(m->position().toPoint().y())); } void QColorLuminancePicker::mousePressEvent(QMouseEvent *m) @@ -914,6 +918,10 @@ void QColorPicker::setCol(int h, int s) void QColorPicker::mouseMoveEvent(QMouseEvent *m) { QPoint p = m->position().toPoint() - contentsRect().topLeft(); + if (m->buttons() == Qt::NoButton) { + m->ignore(); + return; + } setCol(p); emit newCol(hue, sat); }