Derek
Derek

Reputation: 3355

Avoid application activation and focus in when clicking buttons on it - Windows API or Qt

Situation: A border-less QDialog stays successfully on top of other applications.

The problem is when clicking on this always-on-top application window, the following occurs:

Is there a possibility that when clicking on this always-on-top inactive and unfocused application window,

I'm working with Qt but there's no problem about using native Windows API.

I tried the following Qt windowFlag:

Upvotes: 7

Views: 4957

Answers (2)

Derek
Derek

Reputation: 3355

It is possible to make a window unactivable and unfocusable when clicking on it by using Windows flags (#include <qt_windows.h>). The following has to be used after the window is created and shown:

HWND winHandle = (HWND)winId();
ShowWindow(winHandle, SW_HIDE);
SetWindowLong(winHandle, GWL_EXSTYLE, GetWindowLong(winHandle, GWL_EXSTYLE)
    | WS_EX_NOACTIVATE | WS_EX_APPWINDOW);
ShowWindow(winHandle, SW_SHOW);

Upvotes: 7

headsvk
headsvk

Reputation: 2796

I don't know about QDialog, I'm using just a QWidget for similar purpose (displaying a Windows 8 style notification).

Try setting:

dialog->setFocusPolicy(Qt::NoFocus);
dialog->setAttribute(Qt::WA_ShowWithoutActivating); 

maybe you'll have to set focus policy on all children.

Upvotes: 1

Related Questions