windows 如何创建一个以 HWND 为父级的 QWidget?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/293774/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a QWidget with a HWND as parent?
提问by Anders Sandvig
With wxWidgets I use the following code:
使用 wxWidgets 我使用以下代码:
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.
我如何在 Qt 中做同样的事情?这HWND
是我想要作为新 QtWidget 的父窗口的窗口句柄。
采纳答案by sep
Use the create method of QWidget.
使用 QWidget 的 create 方法。
HWND main_window = ...
...
QWidget *w = new QWidget();
w->create((WinId)main_window);
回答by ChrisN
Have you tried the QWinWidget
class from the Qt/MFC Migration Framework?
您是否尝试过Qt/MFC 迁移框架中的QWinWidget
课程?