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. ORACLE 内置函数之 GREATEST 和 LEAST(转)

    Oracle比较一列的最大值或者最小值,我们会不假思索地用MAX和MIN函数,但是对于比较一行的最大值或最小值呢?是不是日常用的少,很多人都不知道有ORACLE也有内置函数实现这个功能:COALESC ...

  2. Oracle的decode、sign、trunc函数

    原文http://knowyouknowme.iteye.com/blog/574974 一.decode 在Oracle/PLSQL中,  decode 具有和 IF-THEN-ELSE 一样的功能 ...

  3. 使用OClint进行iOS项目的静态代码扫描

    使用OClint进行iOS项目的静态代码扫描 原文链接:http://blog.yourtion.com/static-code-analysis-ios-using-oclint.html 最近需要 ...

  4. ZegGraph属性含义

    一.主要内容概念 属性名称 属性值.作用 MasterPane 一个类对象管理多个GraphPane来源于PaneBase.使用MasterPane类都是可选的,GraphPane类可以直接用于一个单 ...

  5. goto语句引起的crosses initialization of XXX

    1. 背景 goto语句虽然目前已经不提倡使用,但是用起来还是很方便,尤其是老代码中见的比较多. 在改动有goto语句的老代码时需要特别注意,是否跳过来资源的释放.有用变量的初始化等等. 很久之前写c ...

  6. angular default project (angular.json的解读)

    Change the default Angular project Understanding it's purpose and limits Klaus KazlauskasFollow Nov ...

  7. 职场之KPI

    当一个公司开始执行KPI考核的时候,任何人的工作性质就发生了变化,而处于底层的员工就惨了,因为一个公司的资源是有限的,一个人的精力也是有限的,当你和你上司负责不同的项目时,而当你的所谓产品经理负责两个 ...

  8. web打印控件Lodop轻松输出清晰的图表和条码

    一.仅用两行语句实现极其复杂的图表打印.类似如下两句: LODOP.ADD_PRINT_CHART(0,0,400,400,5,document.getElementByI d('table001') ...

  9. llvm pass

    https://polly.llvm.org/docs/Architecture.html#polly-in-the-llvm-pass-pipeline

  10. 每天一个linux命令(1):pwd命令

    1.命令简介 pwd(print work directory 打印当前目录)命令以绝对路径的方式显示用户当前工作目录. 2.用法 pwd [-LP] 3.选项 -L --logical 当目录为连接 ...