[Interest] New window in Qt makes the application activate

John Weeks john at wavemetrics.com
Mon Feb 3 19:23:42 CET 2014

On 03-Feb-2014, at 9:35 AM, Konrad Rosenbaum wrote:

> Out of curiosity: what was the problem? Maybe it's a common pitfall that 
> others should be warned about...

I don't know how common it might be.

As part of a (partly mistaken) emulation of some ancient Macintosh API's I was calling QWidget::activateWindow(). If the application is not active, that both makes the window active, and it makes the application active. I guess it's debatable whether activateWindow() should activate the application. I expected that it would just make the window the active window (painted with active appearance, ready to accept focus, title bar buttons with active appearance, etc.) or ready to be the active window when the application activated. The application can be activated via a click in the Dock icon, which doesn't select a window to be the active window, so whatever was active (or made active when the application is not active?) previously now becomes the active window.

I now check to see if the application is active before calling activateWindow(). But that is harder than you might suppose... I was unable to find any Qt call to ask if the application is active, so I now monitor  QEvent::ApplicationActivate and  QEvent::ApplicationDeactivate and set a flag in my QApplication-derived object.

Note that simply showing a floating window activates the application. 

-John Weeks

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140203/a3e95d70/attachment.html>

More information about the Interest mailing list