diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index 1844232efe..3548ec0199 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -142,6 +142,8 @@ QT_BEGIN_NAMESPACE \value DialogSnapToDefaultButton (bool) Whether the mouse should snap to the default button when a dialog becomes visible. + \value ContextMenuOnMouseRelease (bool) Whether the context menu should be shown on mouse release. + \sa themeHint(), QStyle::pixelMetric() */ @@ -487,6 +489,7 @@ QVariant QPlatformTheme::defaultThemeHint(ThemeHint hint) case IconPixmapSizes: return QVariant::fromValue(QList()); case DialogSnapToDefaultButton: + case ContextMenuOnMouseRelease: return QVariant(false); } return QVariant(); diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h index 4bddac5b1b..5cdec48ca3 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -106,7 +106,8 @@ public: TabAllWidgets, IconPixmapSizes, PasswordMaskCharacter, - DialogSnapToDefaultButton + DialogSnapToDefaultButton, + ContextMenuOnMouseRelease }; enum DialogType { diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index eb1bbd1ab0..00a5da8f44 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -383,6 +383,8 @@ QVariant QWindowsTheme::themeHint(ThemeHint hint) const } case DialogSnapToDefaultButton: return QVariant(booleanSystemParametersInfo(SPI_GETSNAPTODEFBUTTON, false)); + case ContextMenuOnMouseRelease: + return QVariant(true); default: break; } diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 2e96247873..167102c633 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -49,6 +49,7 @@ #endif #include #include +#include #include QT_BEGIN_NAMESPACE @@ -354,6 +355,9 @@ void QWidgetWindow::handleNonClientAreaMouseEvent(QMouseEvent *e) void QWidgetWindow::handleMouseEvent(QMouseEvent *event) { + static const QEvent::Type contextMenuTrigger = + QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::ContextMenuOnMouseRelease).toBool() ? + QEvent::MouseButtonRelease : QEvent::MouseButtonPress; if (qApp->d_func()->inPopupMode()) { QWidget *activePopupWidget = qApp->activePopupWidget(); QWidget *popup = activePopupWidget; @@ -438,7 +442,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) } qt_replay_popup_mouse_event = false; #ifndef QT_NO_CONTEXTMENU - } else if (event->type() == QEvent::MouseButtonPress + } else if (event->type() == contextMenuTrigger && event->button() == Qt::RightButton && (openPopupCount == oldOpenPopupCount)) { QWidget *popupEvent = popup; @@ -487,7 +491,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) qt_last_mouse_receiver); #ifndef QT_NO_CONTEXTMENU - if (event->type() == QEvent::MouseButtonPress && event->button() == Qt::RightButton) { + if (event->type() == contextMenuTrigger && event->button() == Qt::RightButton) { QContextMenuEvent e(QContextMenuEvent::Mouse, mapped, event->globalPos(), event->modifiers()); QGuiApplication::sendSpontaneousEvent(receiver, &e); }