This thread is 4 years old, but I want to give a solution anyway.
I spent the past 2 months trying to figure out how to do this, and all the threads I found are talking about issues but nobody gave me a solution.
Actually, the QWidget you create has its own focus but is not "parent" of the HWND you are embedding on it, so you have to make the keyboard focus by yourself.
The best way to do that is by using the SetFocus function of the winuser library (WinUser.h):
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setfocus
Like, in example:
m_qwindow = QWindow::fromWinId(m_handle); m_widget = QWidget::createWindowContainer(m_qwindow, this); // tell the os to focus the viewport window SetFocus(m_handle);with m_handle being the HWND (or WId) used to create the QWindow.
Unfortunately, this solution works only on windows (but maybe there are equivalents on another os).
It also doesn't work when clicking on the embedded window, because it isn't owned by Qt.
maybe you can try to mess with QFocusFrame (I haven't tried this at all, but it should be a way to use it as a fix by putting it over the embedded window)
or, if the window you are embedding is one of your creations, put the SetFocus() function in its code, as a callback when clicked.
I hope that even with 4 years late, this solution is still helping the desperate developers like who I was the past two months.