[ACCEPTED]-Show window in Qt without stealing focus-active-window

Accepted answer
Score: 74

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

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

Score: 11

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

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

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

Score: 3

Widgets don't accept focus by default but 9 presumably you haven't created a plain widget? Which 8 subclass was it? QMainWindow or something 7 else?

It's possible the window subclasses 6 default to accepting focus so try explicitly 5 calling QWidget::setFocusPolicy with Qt::NoFocus 4 before calling QWidget::show().

Also, make 3 sure you're not calling QWidget::activateWindow() on 2 the window or any of its widgets at any 1 point.

More Related questions