Qt3D 设置窗口背景颜色和图案

最近在用 Qt3D 做三维显示,需要设置窗口Qt3DWindow背景的颜色,
查了一些资料,做一些整理,备查。

设置窗口的颜色

如果只是最简单的需求设置某一种颜色,可以直接调用 defaultFramGraph()的 setClearColor 方法。

Qt3DExtras::Qt3DWindow *window = new Qt3DExtras::Qt3DWindow();
window -> defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d9f)));

参考 stackoverflow

复杂背景的设置

  1. Qt 的例子中提供了一个波浪形背景的设置,通过手写vertex Shader 和 fragment shader 实现的;要使用这种方法,需要有 OpenGL的基础知识。
    详情可以参考: https://doc.qt.io/archives/qt-5.10/qt3d-wave-example.html
    可以参照这个例子给我更加复杂的图案的例子。
  2. 设置背景图案。 在 github 中 florianblume 实现了一个在 Qt3D scene 中添加背景图像的 demo.
    详情参考 https://github.com/florianblume/Qt3D-BackgroundImage
原文地址:https://www.cnblogs.com/sunchaothu/p/10843049.html