Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to create a window without focus all the time?
Forum Updated to NodeBB v4.3 + New Features

How to create a window without focus all the time?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 751 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chinanoahli
    wrote on last edited by
    #1

    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, using Qt::WindowStaysOnTopHint will work), and it will never takes focus.

    I tried Qt::WA_ShowWithoutActivating, Qt::WindowDoesNotAcceptFocus and Qt::NoFocus, but none of them works.

    Thanks.

    1 Reply Last reply
    0
    • SamurayHS Offline
      SamurayHS Offline
      SamurayH
      wrote on last edited by SamurayH
      #2

      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.

      "قال رسول الله صلى الله عليه وسلم : " أحب الناس إلى الله أنفعهم للناس

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved