diff options
author | Shawn Rutledge <[email protected]> | 2024-12-09 22:16:37 +0100 |
---|---|---|
committer | Kai Uwe Broulik <[email protected]> | 2024-12-10 22:57:57 +0100 |
commit | 357c64a99607456133bfabf86d6b67162717cb29 (patch) | |
tree | b44ad8406ed62174c59d46a0bb6ca9be193f8eec /src/widgets/kernel/qwidgetwindow.cpp | |
parent | f3d5bdf4bcfe26a17b1b3de07a345586c37263c0 (diff) |
QWidgetWindow: send QContextMenuEvent even after accepted mouse press
It would be more consistent if we could rely on the accepted state of
the original QMouseEvent to decide whether to follow up with a
QContextMenuEvent; but not all Qt widgets call ignore() on unhandled
mouse events, both in Qt and in external libraries and applications
(including some from KDE). So we should at least wait until Qt 7 to
make this a requirement. It seems sensible to move the check into
QWindow::event() rather than trying to distinguish the window type in
maybeSynthesizeContextMenuEvent(). We merely output a categorized log
message to indicate when the legacy behavior is in effect.
Amends 84a5f50c7766c99f62b22bb4388137e0aa8dd13d
[ChangeLog][QtWidgets] If your QWidget subclass depends on receiving
QContextMenuEvent, and also handles mouse events directly, we
recommend that you call ignore() on unhandled mouse events (such as
right-button events). In Qt 7, we plan to stop sending
QContextMenuEvent if the triggering mouse event is accepted.
Fixes: QTBUG-132066
Pick-to: 6.9
Change-Id: I454813dab4c387112f161fc28a0ee94570013afa
Reviewed-by: Volker Hilsheimer <[email protected]>
Reviewed-by: Mitch Curtis <[email protected]>
Diffstat (limited to 'src/widgets/kernel/qwidgetwindow.cpp')
-rw-r--r-- | src/widgets/kernel/qwidgetwindow.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index d337679fb2d..0565835e38b 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -666,7 +666,13 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) event->setAccepted(translated.isAccepted()); } - d->maybeSynthesizeContextMenuEvent(event); +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) + if ( +#else + if (event->isAccepted() && +#endif + (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease)) + d->maybeSynthesizeContextMenuEvent(event); } void QWidgetWindow::handleTouchEvent(QTouchEvent *event) |