简体   繁体   English

Qt小部件与QML混合在一起

[英]Qt widgets mixed with QML on top

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. 我想使用两个小部件(一次一个)作为我的应用程序的基础/背景,在它上面有一个QML UI和一个无边框窗口。 It should look like this: 它应该如下所示:

layout http://fs1.directupload.net/images/141211/cruvrltu.png 布局http://fs1.directupload.net/images/141211/cruvrltu.png

  1. An OpenGL-based scanning component 基于OpenGL的扫描组件
  2. A 3D visualization component operating via window handle 通过窗口手柄操作的3D可视化组件
  3. Several QML UI components as overlays (possibly draggable) 几个QML UI组件作为叠加(可能是可拖动的)
  4. QML sidebar component QML侧边栏组件

I have successfully achieved to include component 1 into a QGLWidget and have the QML components displayed on top of it. 我已经成功地将组件1包含到QGLWidget中,并在其上显示QML组件。 Worked without a problem. 工作没有问题。

However, I fail to make component 2 work. 但是,我无法使组件2工作。 I can do it easily if I include it into a top-level QWidget and use its winId to access the handle. 如果我将它包含在顶级QWidget中并使用其winId来访问句柄,我可以轻松完成。 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. 如果我采用QWidget方式,则组件位于顶部,QML组件无法覆盖。
  • I tried to make it work with a QGraphicsProxyWidget, but it just displays an empty gray widget. 我尝试使用QGraphicsProxyWidget,但它只显示一个空的灰色小部件。
  • I read that the new(er) way is to use a QWidget-based application and use QtQuick2 for overlays. 我读到新的(呃)方法是使用基于QWidget的应用程序并使用QtQuick2进行叠加。 But again, it only seems to work for OpenGL-based components. 但同样,它似乎只适用于基于OpenGL的组件。
  • 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. 可能还有使用QQuickWidget和QOpenGLWidget的选项,可在Qt 5.3和5.4中找到,但我不知道如何以及它是否有效,因为我没有看到任何符合我目的的例子。
  • There would also be the option of QWidget::createWindowContainer , but it does not allow (transparent) overlays. 还有QWidget::createWindowContainer的选项,但它不允许(透明)叠加。

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). 我的问题是我不知道如何用QML覆盖非GL小部件,然后如何将所有内容都包含在一个应用程序中(当在两个小部件之间切换时, setViewport可能存在父问题)。 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. 我正在使用Qt 5.2.1,VS2012和针对x64(需求)构建,针对Windows桌面。

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. 拥有一个高性能的解决方案当然是好的,可能基于QtQuick2,但是我很遗憾,我会接受任何至少会让它暂时工作的东西。

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). 最后,我使用QWindow,使用其窗口句柄来集成3D可视化,然后将其与QQuickView组件(QWindow作为父组件)重叠。 The only drawback of that solution is that it does not allow for transparency. 该解决方案的唯一缺点是它不允许透明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM