3
votes

I would like to use two widgets (one at a time) as the basis/background of my application, with a QML UI on top of it and a borderless window. It should look like this:

layout

  1. An OpenGL-based scanning component
  2. A 3D visualization component operating via window handle
  3. Several QML UI components as overlays (possibly draggable)
  4. QML sidebar component

I have successfully achieved to include component 1 into a QGLWidget and have the QML components displayed on top of it. Worked without a problem.

However, I fail to make component 2 work. I can do it easily if I include it into a top-level QWidget and use its winId to access the handle. Unfortunately, I cannot build on top of that. I went through several options, but none of them seems to suffice:

  • If I go the QWidget way, the component is on top and QML components cannot overlay.
  • I tried to make it work with a QGraphicsProxyWidget, but it just displays an empty gray widget.
  • I read that the new(er) way is to use a QWidget-based application and use QtQuick2 for overlays. But again, it only seems to work for OpenGL-based components.
  • There is maybe also the option to use QQuickWidget and QOpenGLWidget, available in Qt 5.3 and 5.4, but I have no clue how and if it works as I have seen no examples that would fit my purpose.
  • There would also be the option of QWidget::createWindowContainer, but it does not allow (transparent) overlays.

My problem is that I don't know how to overlay a non-GL widget with QML and then later how to include everything into one application (possible parent problems with setViewport when switching between the two widgets). Has anyone ever done this or can point in a direction which might show results?

I am using Qt 5.2.1, VS2012 and build for x64 (requirement), targeting Windows desktop.

It would of course be good to have a performant solution, maybe based on QtQuick2, but I am at such a loss that I would accept anything that at least would make it work for the moment.

1
Just use QQuickWidget - it is basically a widget in which you can put QML. You will have to update your Qt version to at least 5.3, 5.4 final was released yesterday. - dtech
I just finished downloading 5.3.2 and will try it asap. - Franz B.
I have tried my best, but I just cannot get it to run. I found "qquickviewcomparison" by a Qt developer and it looks like it's the right thing. However, it just shows that you can overlay FBO over an OpenGL/QML scene. I need QML on top of a non-OpenGL widget bound to a 3rd party visualization. Also, QQuickWidget docs explicitly tell you to "avoid calling winId() on a QQuickWidget. This function triggers the creation of a native window, resulting in reduced performance and possibly rendering glitches". But I need winId to integrate that non-OpenGL widget. - Franz B.
I really wonder why there is apparently no well-established solution to this, since it's a fairly common procedure for a UI framework. Seems like they aim only for the OpenGL world. Real bummer for me... - Franz B.
Try the QQuickRenderControl class - it allows to render QtQuick in an offscreen buffer which you can use as a texture to put wherever you want. - dtech

1 Answers

2
votes

In the end, I went with using a QWindow, take its window handle for integrating the 3D visualization and then overlaying it with QQuickView components (with the QWindow as parent). The only drawback of that solution is that it does not allow for transparency.