问题描述
现在建议使用QWindow进行OpenGL绘制.是否可以在此窗口中添加小部件?如果是这样,怎么办?如果没有,我应该如何使用Qt5将小部件添加到OpenGL程序中?
It's now recommended to use QWindow for OpenGL drawing. Is it possible to add a widget to this window? If so, how? If not, how should I go about adding widgets to an OpenGL program using Qt5?
推荐答案
应用程序通常将QWidget
或QQuickView
用于其UI,而不直接使用QWindow
. QWindow
比QWidget
更低电平.如果要直接使用QWindow
,则需要完成更多工作.您应该手动完成所有与绘图相关的操作,这并不容易.
An application will typically use QWidget
or QQuickView
for its UI, and not QWindow
directly. QWindow
is more low level than QWidget
. If you want to use QWindow
directly, more work is needed to accomplish the job. You should manually do all drawing related things which is not easy.
但是,如果您确实希望使用QWindow
/QGuiApplication
而不是QWidget
/QApplication
,则可以使用 QBackingStore 由QWidget
使用,或SceneGraph
由SceneGraph
在QWindow::exposeEvent()
中使用.
However, if you really want a QWindow
/QGuiApplication
instead of QWidget
/QApplication
, you can use QBackingStore which is used by QWidget
, or SceneGraph
which is used by QQuick
in QWindow::exposeEvent()
.
您可以使用QPainter
QWindow的应用程序的示例="nofollow">此处.
You can see an example of a minimal QWindow
based application using QPainter
here.
这篇关于可以将QWidgets添加到QWindow吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!