summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2023-01-12 14:07:41 +0100
committerAxel Spoerl <axel.spoerl@qt.io>2023-01-21 17:04:14 +0100
commit7689d4ad2f673317af432aae498da74d13703126 (patch)
treea4cf024994e679a72c26c03247c1b43a8db6ef7d /src/widgets
parentb6224ec8fa68387af344fc1610b4932c9aed6143 (diff)
QWidgetTextControl: Ignore unconsumed mouse release events
QWidgetTextControlPrivate::mouseReleaseEvent() has early returns implemented, e.g. when link has been right clicked or no selection anchor has been found. These early returns, however, still consume the event. This leads to events getting lost instead of getting propagated: As an example, a QLabel with rich text uses QWidgetTextControl. While it propagates mouse press events back to its parent, mouse release events get lost. A QLabel with plain text propagates both events back correctly. This patch adds QEvent::ignore() to the early return. Since no test class exists for QWidgetTextControl, it adds a test in tst_QLabel. Fixes: QTBUG-110055 Pick-to: 6.5 6.4 Change-Id: I950f8c3f135793b01c59832835bb429db2282169 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/widgets/qwidgettextcontrol.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp
index 4f008fe24f..a4679402dc 100644
--- a/src/widgets/widgets/qwidgettextcontrol.cpp
+++ b/src/widgets/widgets/qwidgettextcontrol.cpp
@@ -1818,25 +1818,36 @@ void QWidgetTextControlPrivate::mouseReleaseEvent(QEvent *e, Qt::MouseButton but
}
if (interactionFlags & Qt::LinksAccessibleByMouse) {
- if (!(button & Qt::LeftButton))
+
+ // Ignore event unless left button has been pressed
+ if (!(button & Qt::LeftButton)) {
+ e->ignore();
return;
+ }
const QString anchor = q->anchorAt(pos);
- if (anchor.isEmpty())
+ // Ignore event without selection anchor
+ if (anchor.isEmpty()) {
+ e->ignore();
return;
+ }
if (!cursor.hasSelection()
|| (anchor == anchorOnMousePress && hadSelectionOnMousePress)) {
const int anchorPos = q->hitTest(pos, Qt::ExactHit);
- if (anchorPos != -1) {
- cursor.setPosition(anchorPos);
- QString anchor = anchorOnMousePress;
- anchorOnMousePress = QString();
- activateLinkUnderCursor(anchor);
+ // Ignore event without valid anchor position
+ if (anchorPos < 0) {
+ e->ignore();
+ return;
}
+
+ cursor.setPosition(anchorPos);
+ QString anchor = anchorOnMousePress;
+ anchorOnMousePress = QString();
+ activateLinkUnderCursor(anchor);
}
}
}