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 <Friedemann.Kleint@qt.io>
This commit is contained in:
Andy Shaw 2020-02-26 13:00:42 +01:00
parent de1d51a3fd
commit 09c5dfb732

View File

@ -424,10 +424,14 @@ 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;
case NIN_BALLOONUSERCLICK:
emit messageClicked();