--- qnsview.mm 2014-04-30 12:57:10.000000000 -0700 +++ qnsview_new.mm 2014-04-30 12:56:24.000000000 -0700 @@ -479,7 +479,17 @@ { if (m_window->flags() & Qt::WindowTransparentForInput) return NO; - QWindowSystemInterface::handleWindowActivated([self topLevelWindow]); + + // Don't blindly activate the top level window. Activate it if and only if + // the top level window (or a child widget of it) is meant to accept the + // keyboard focus. Context menu for instance is a prime example that can + // be the first responder for events but never want to be the active window. + + QWindow *topWindow = [self topLevelWindow]; // guaranteed to be non-null + QCocoaWindow *cocoaWindow = static_cast(topWindow->handle()); + if (cocoaWindow && cocoaWindow->m_nsWindow && [cocoaWindow->m_nsWindow canBecomeKeyWindow]) + QWindowSystemInterface::handleWindowActivated(topWindow); + return YES; }