QT中自带的例子widgets-scene3d实现在基于Widget的应用程序中使用qml 3d场景的功能,我在此基础上,将basicshapes-cpp的例子加以嵌入:

相关代码如下:

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
 
#include <QApplication>
#include <QMainWindow>
#include <QQuickWidget>
#include <QMdiArea>
#include <QLCDNumber>
#include <QMenuBar>
#include "scenemodifier.h"
#include <Qt3DRender/qcamera.h>
#include <Qt3DCore/qentity.h>
#include <Qt3DRender/qcameralens.h>
#include <Qt3DInput/QInputAspect>

#include <Qt3DExtras/qtorusmesh.h>
#include <Qt3DRender/qmesh.h>
#include <Qt3DRender/qtechnique.h>
#include <Qt3DRender/qmaterial.h>
#include <Qt3DRender/qeffect.h>
#include <Qt3DRender/qtexture.h>
#include <Qt3DRender/qrenderpass.h>
#include <Qt3DRender/qsceneloader.h>
#include <Qt3DRender/qpointlight.h>

#include <Qt3DCore/qtransform.h>
#include <Qt3DCore/qaspectengine.h>

#include <Qt3DRender/qrenderaspect.h>
#include <Qt3DExtras/qforwardrenderer.h>

#include <Qt3DExtras/qt3dwindow.h>
#include <Qt3DExtras/qfirstpersoncameracontroller.h>

int main(int argc, char **argv)
{
    QApplication app(argc, argv);

QMainWindow mainWindow;

QMdiArea *centralWidget = new QMdiArea;
    // 子窗口1
    QLCDNumber *lcd = new QLCDNumber;
    lcd->display();
    lcd->setMinimumSize();
    centralWidget->addSubWindow(lcd);
    // 子窗口2
    QQuickWidget *quickWidget = new QQuickWidget;
    quickWidget->setMinimumSize();
    quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
    quickWidget->setSource(QUrl("qrc:/main.qml"));
    centralWidget->addSubWindow(quickWidget);
    // 子窗口3
    Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow();
    view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f)));
    QWidget *container = QWidget::createWindowContainer(view);
    container->setMinimumSize();
    centralWidget->addSubWindow(container);

Qt3DInput::QInputAspect *input = new Qt3DInput::QInputAspect;
    view->registerAspect(input);

// Root entity
    Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity();
    // Camera
    Qt3DRender::QCamera *cameraEntity = view->camera();
    cameraEntity->lens()->setPerspectiveProjection(.0f);
    cameraEntity->setPosition(QVector3D(.0f));
    cameraEntity->setUpVector(QVector3D());
    cameraEntity->setViewCenter(QVector3D());

Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity);
    Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity);
    light->setColor("white");
    light->setIntensity();
    lightEntity->addComponent(light);
    Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity);
    lightTransform->setTranslation(cameraEntity->position());
    lightEntity->addComponent(lightTransform);

// For camera controls
    Qt3DExtras::QFirstPersonCameraController *camController = new Qt3DExtras::QFirstPersonCameraController(rootEntity);
    camController->setCamera(cameraEntity);
    // Scenemodifier
    SceneModifier *modifier = new SceneModifier(rootEntity);

// Set root object of the scene
    view->setRootEntity(rootEntity);

mainWindow.setCentralWidget(centralWidget);

QMenu *fileMenu = mainWindow.menuBar()->addMenu(QObject::tr("&File"));
    fileMenu->addAction(QObject::tr("E&xit"), qApp, &QCoreApplication::quit);

mainWindow.resize();
    mainWindow.show();

return app.exec();
}

再进一步,我将QT场景视图(Graphics-View)嵌入多文档界面,下面尝试将QT自带的boxes例子(GraphicsView With OpenGL)嵌入,相关代码如下:

 C++ Code 
1
2
3
4
5
6
7
8
9
10
 
// 子窗口4-GraphicsView With OpenGL
QGLWidget *widget = new QGLWidget(QGLFormat(QGL::SampleBuffers));
widget->makeCurrent();
Scene scene(1024, 768, maxTextureSize);;
GraphicsView view;
view.setViewport(widget);
view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
view.setScene(&scene);
//gview.show();
centralWidget->addSubWindow(&gview);

我在Ubuntu中测试的一个截图效果如下:

QT 中Widgets-Scene3d例子学习的更多相关文章

  1. PyQt学习随笔:Qt中Model/View中的怎么构造View匹配的Model

    老猿Python博文目录 老猿Python博客地址 在<PyQt学习随笔:Qt中Model/View相关的主要类及继承关系>介绍了Model/View架构的主要类,在实际使用时,view相 ...

  2. PyQt(Python+Qt)学习随笔:快速理解Qt 中Action是什么

    一.引言 Qt中Action这个词接触很久了,一直以来没去学习,今天终于准备学习了,查了些资料,初步总结为: Action为界面操作的抽象,应用程序可以通过菜单,工具栏按钮以及键盘快捷键来调用通用的命 ...

  3. Qt学习笔记:Qt中使用Lua

    今天想在Qt中使用Lua进行数据操作 结果发现在Qt中使用Lua的文章较少,虽然很简单,但是还是写出来提供入门,顺便记录一下 我使用的是Qt Creator 3.4.2,用的是mingw4.9.2的编 ...

  4. OpenCV2学习笔记03:Qt中配置OpenCV环境

    在Qt中开发基于OpenCV的应用时,需要配置对应函数库到环境变量,这时候我们需要使用到qmake能够识别的变量来指定环境变量. INCLUDEPATH: 用于指定搜索头文件到文件夹路径. LIBS: ...

  5. QT中静态库的生成与使用——创建共享库代码,附例子

    一. 静态库的生成    1. 测试目录: lib    2. 源码文件名: mywindow.h, mywindow.cpp, 类MyWindow继承于QPushButton, 并将文字设置为&qu ...

  6. <QT之Bug制造机>QT中串口类“QSerialPort”的学习笔记

    QT5中已经增加了串口类QSrialPort,可以直接调用API函数进行快速开发. 1. 获取串口信息 Dialog::Dialog(QWidget *parent) : QDialog(parent ...

  7. PyQt学习随笔:Qt中Model/View中的Model Index

    Qt中Model/View中的Model Index是一个类,该类用于定位Model/View中数据模型中的数据. Model Index是从QAbstractItemModel派生的子类,用于在项视 ...

  8. PyQt(Python+Qt)学习随笔:Qt中的部分类型QString、QList和指针、引用在PyQt中的实现方式

    老猿Python博文目录 老猿Python博客地址 在我们查阅Qt的文档资料时,可以看到Qt中的链表使用的是QList,字符串使用的是QString,但老猿在测试时发现这两个类型PyQt不支持,无法找 ...

  9. Qt学习日记篇-Qt中使用Curl和jsonCpp

    1.Qt中安装并使用jsonCPP库 1.1  官网下载.https://sourceforge.net/projects/jsoncpp/    解压文件得到 jsoncpp-src-0.5.0 文 ...

随机推荐

  1. [P3768]简单的数学题

    Description: 求出\((\sum_{i=1}^n \sum_{j=1}^n ij\ gcd\ (i,j)) mod\ p\) Hint: \(n<=10^{10}​\) Soluti ...

  2. LOJ6041 SAM+set+树状数组

    首先对于原串建$SAM$,我们可以发先在一个点$i$的$right$集合里的点的相似度就是$len[i]$,于是可以将$SAM$的$right$集合通过$set$来启发式合并,每次加入新的点对$(i, ...

  3. 几种Unity运行平台的判断

    这里就介绍几种常见的,也是便于使用的几种平台判断的方法. 1.先说第一种,也是我用的顺手的一个.利用RuntimePlatform判断,API上的解释是[The platform applicatio ...

  4. Oracle中使用透明网关链接到Sqlserver(转)

    测试环境介绍 1.ORACLEServer   Database version:10.2.0 IP:192.168.1.5 ORACLE_HOME:D:\oracle\product\10.2.0\ ...

  5. 从安装node js到构建一个vue并启动它

    1.安装node js 下载地址:http://nodejs.cn/download/2.安装完成后运行Node.js command prompt(node -v查看安装版本) 3.安装npm(由于 ...

  6. 什么叫做GNU

    GNU就是GNU's Not Unix的缩写, GNU 的创始人Stallman 认为UNIX 虽然不是最 好的操作系统,但是至少不会太差,而他自信有能力把UNIX不足的地方加以改进,使它 成为一个优 ...

  7. verilog语法实例学习(13)

    verilog代码编写指南 变量及信号命名规范  1. 系统级信号的命名.  系统级信号指复位信号,置位信号,时钟信号等需要输送到各个模块的全局信号:系统信号以字符串Sys开头.  2. 低电平有效的 ...

  8. 奇怪吸引子---NewtonLeipnik

    奇怪吸引子是混沌学的重要组成理论,用于演化过程的终极状态,具有如下特征:终极性.稳定性.吸引性.吸引子是一个数学概念,描写运动的收敛类型.它是指这样的一个集合,当时间趋于无穷大时,在任何一个有界集上出 ...

  9. Java access to the Domino Objects, Part 1

    From: https://www.ibm.com/developerworks/lotus/library/ls-Java_access_pt1/index.html Overview Java a ...

  10. 从Encoder到Decoder实现Seq2Seq模型

    https://zhuanlan.zhihu.com/p/27608348 更新:感谢@Gang He指出的代码错误.get_batches函数中第15行与第19行,代码已经重新修改,GitHub已更 ...