We have a desktop windows application that uses a component that needs a HWND
to be displayed. In a WPF application we use a HwndHost
to display it. We are trying to make a Qt QML based application to do the same.
Is it possible to host a HWND
component in a QML application?
It works with a QQuickWindow
, but the control I attach takes the entire window application area. I would like to bind to a smaller area, like the rectArea
in the QML below. But a QQuickItem
does not have a windId()
, only its parent window()
. It is possible?
Here is my QML:
ApplicationWindow {
width: 640
height: 480
visible: true
Rectangle {
objectName: "rectArea"
id: rectangle1
x: 0
y: 0
width: 200
height: 200
color: "#ffffff"
}
}
And here a cpp snippet:
void setHwnd(QQmlApplicationEngine& m_engine) {
auto root_objects = m_engine.rootObjects();
m_rootObject = root_objects[0];
auto rect_area = m_rootObject->findChild<QQuickItem*>("rectArea");
HWND hWnd = reinterpret_cast<HWND>(rect_area->window()->winId());
// use hWnd here, but it takes the entire window area...
}