Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Host a HWND component in a QML application
QtWS25 Last Chance

Host a HWND component in a QML application

Scheduled Pinned Locked Moved QML and Qt Quick
qmlhwnd
2 Posts 2 Posters 2.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    spiovesan
    wrote on 14 May 2015, 12:07 last edited by spiovesan
    #1

    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.

    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... }•

    1 Reply Last reply
    0
    • S Offline
      S Offline
      ssolomin
      wrote on 17 May 2015, 13:02 last edited by
      #2

      Hello,
      I can only share my experiences. My "teacher" was this example. Yes, you can get HWND of window only. You should implement paint() method like example and render your content into the area occupied by the element. Area for rendering can be chosen as glViewport(x(), windowHeight - y() - height(), width(), height());. But (as I've understood) QQuickWindow has only two time for rendering: beforeRendering & afterRendering: it mean you can have only top or bottom rendered item.
      Then, I've found second way for rendering: render to FBO and draw as QQuickFramebufferObject. More information is here.

      1 Reply Last reply
      0

      2/2

      17 May 2015, 13:02

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved