From 09c5dfb73271614eb55c6d6c610c873fc9146a2f Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 26 Feb 2020 13:00:42 +0100 Subject: Windows: Enable closing the system tray menu when clicking outside of it In order for the system to close a menu when clicking outside of it or outside of the controlling window for the system tray then it needs to be at the foreground right before the menu is tracked. This makes it act like other system tray menus then. Change-Id: I663670c506cfd1e2ba59cd3e75b12e1f8ba17c33 Reviewed-by: Friedemann Kleint --- src/plugins/platforms/windows/qwindowssystemtrayicon.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms/windows/qwindowssystemtrayicon.cpp') diff --git a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp index ab830e1461..9409d2db4d 100644 --- a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp +++ b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp @@ -424,8 +424,12 @@ bool QWindowsSystemTrayIcon::winEvent(const MSG &message, long *result) if (screen) { emit contextMenuRequested(globalPos, screen); emit activated(Context); - if (m_menu) + if (m_menu) { + // Set the foreground window to the controlling window so that clicking outside + // of the menu or window will cause the menu to close + SetForegroundWindow(m_hwnd); m_menu->trackPopupMenu(message.hwnd, globalPos.x(), globalPos.y()); + } } } break; -- cgit v1.2.3