How to create a window without focus all the time?
-
I need to create a window(only for Windows) just like MS Windows build in screen keyboard.
It can keep itself on top(this is easy, usingQt::WindowStaysOnTopHint
will work), and it will never takes focus.I tried
Qt::WA_ShowWithoutActivating
,Qt::WindowDoesNotAcceptFocus
andQt::NoFocus
, but none of them works.Thanks.
-
I don't think you can achieve your goal using Qt flags. Since you only want to support Windows, then what you're looking for is WS_EX_NOACTIVATE.
Here's a quick example:
#include "myvirtualkeyboard.h" #include <Windows.h> MyVirtualKeyboard::MyVirtualKeyboard(QWidget *parent) : QWidget(parent) { // Add WS_EX_NOACTIVATE and WS_EX_TOPMOST to the default extended style HWND hWnd = (HWND)winId(); LONG_PTR exStyle = GetWindowLongPtr(hWnd, GWL_EXSTYLE); SetWindowLongPtr(hWnd, GWL_EXSTYLE, exStyle | WS_EX_NOACTIVATE | WS_EX_TOPMOST); // ... }
This will give you the exact behavior of the on-screen keyboard. However, if you want to use this keyboard with other windows in the same process (e.g. same Qt app) too, then you still need an extra step.