9

With wxWidgets I use the following code:

HWND main_window = ...
...
wxWindow *w = new wxWindow();
wxWindow *window = w->CreateWindowFromHWND(0, (WXHWND) main_window);

How do I do the same thing in Qt? The HWND is the handle of the window I want as the parent window for the new QtWidget.

Anders Sandvig
  • 20,720
  • 16
  • 59
  • 73

3 Answers3

9

Use the create method of QWidget.

HWND main_window = ...
...
QWidget *w = new QWidget();
w->create((WinId)main_window);
sep
  • 3,409
  • 4
  • 29
  • 32
6

Have you tried the QWinWidget class from the Qt/MFC Migration Framework?

Russ
  • 10,835
  • 12
  • 42
  • 57
ChrisN
  • 16,635
  • 9
  • 57
  • 81
0

How about fromWinId https://doc-snapshots.qt.io/qt6-dev/qwindow.html#fromWinId

Creates a local representation of a window created by another process or by using native libraries below Qt.

Doug Rogers
  • 21
  • 1
  • 3