Avoid activating the application and focusing when you click on the buttons - Windows API or Qt

Situation: QDialog without borders remains successful on top of other applications.

The problem is that when you click on this application window always on top, the following happens:

  • When pressed, pressing is always activated on the top panel.
  • The click-on application window always captures the focus of the previous active / focused application.

Is there a chance that when you click on this inactive and unfocused application window is always on top,

  • current application will not lose activation and focus
  • while the user can still interact with the constantly running application (pressing buttons or drop-down menus, dragging the window)?

I work with Qt, but there is no problem using my own Windows API.

I tried the following Qt windowFlag:

  • Qt::WindowDoesNotAcceptFocus , but it does not work: the always-on-top application is activated, focused.
  • Qt::WindowTransparentForInput , the application is always on top really transparent for clicks: it is not activated and not focused, but the buttons, unfortunately, do not work when hit.
+6
source share
2 answers

You can make a window inactive and uncontrollable when you click on it using the Windows flags ( #include <qt_windows.h> ). The following should be used after creating and displaying the window:

 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); 
+5
source

I don't know about QDialog, I only use QWidget for a similar purpose (displaying a notification in the style of Windows 8).

Try to install:

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

You may need to set a focus policy for all children.

+1
source

Source: https://habr.com/ru/post/953341/


All Articles