Show window in Qt without stealing focus


I'm using the Qt library to show a slideshow on the second monitor when the user isn't using the second monitor. An example is the user playing a game in the first monitor and showing the slideshow in the second monitor.

The problem is that when I open a new window in Qt, it automatically steals the focus from the previous application. Is there any way to prevent this from happening?

6/9/2009 12:29:23 AM

Accepted Answer

It took me a while to find it but I found it: setAttribute(Qt::WA_ShowWithoutActivating);

This forces the window not to activate. Even with the Qt::WindowStaysOnTopHint flag

3/28/2011 9:25:25 PM

If you want to make floating preview box/ any other widget just use below

thumbnail = new QLabel;
thumbnail->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);

Qt::Tool is important flag to make it work. I mean not stealing focus.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow