Anders Sandvig
Anders Sandvig

Reputation: 20986

How to create a QWidget with a HWND as parent?

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.

Upvotes: 9

Views: 8060

Answers (3)

Doug Rogers
Doug Rogers

Reputation: 21

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.

Upvotes: 0

ChrisN
ChrisN

Reputation: 16933

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

Upvotes: 6

sep
sep

Reputation: 3485

Use the create method of QWidget.

HWND main_window = ...
...
QWidget *w = new QWidget();
w->create((WinId)main_window);

Upvotes: 9

Related Questions