Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 544
Anders Sandvig Avatar asked Nov 16 '08 10:11

Anders Sandvig


People also ask

What is QWidget * parent?

The tree-like organization of QWidgets (and in fact of any QObjects ) is part of the memory management strategy used within the Qt-Framework. Assigning a QObject to a parent means that ownership of the child object is transferred to the parent object. If the parent is deleted, all its children are also deleted.

What is QWidget?

The QWidget class is the base class of all user interface objects. The widget is the atom of the user interface: it receives mouse, keyboard and other events from the window system, and paints a representation of itself on the screen. Every widget is rectangular, and they are sorted in a Z-order.

How do you get children of QWidget?

You can use the findChild() function with the object name to get a specific child. You can also use findChildren() to get all the children that have the same name and then iterate through the list using foreach() or QListIterator .


2 Answers

Use the create method of QWidget.

HWND main_window = ...
...
QWidget *w = new QWidget();
w->create((WinId)main_window);
like image 110
sep Avatar answered Sep 22 '22 23:09

sep


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

like image 38
ChrisN Avatar answered Sep 19 '22 23:09

ChrisN