将STL文件添加到QT窗口小部件

时间:2018-04-26 13:14:33

标签: c++ qt qt3d

我正在尝试使用QT5.10和c ++为STL文件创建一个查看器。我过早地在QWindow中查看该文件,但我找不到如何在QWidget中查看该文件。这就是我想做的事情Qt Designer

这是在QWindow中查看它的代码:

Qt3DExtras::Qt3DWindow view;

Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity;
Qt3DCore::QEntity *flyingwedge = new Qt3DCore::QEntity(rootEntity);

Qt3DExtras::QPhongMaterial *material = new Qt3DExtras::QPhongMaterial();
material->setDiffuse(QColor(200, 200, 200));

Qt3DRender::QMesh *stlObjectMesh = new Qt3DRender::QMesh;
stlObjectMesh->setMeshName("Onshape");
stlObjectMesh->setSource(data);
flyingwedge->addComponent(stlObjectMesh);
flyingwedge->addComponent(material);

Qt3DRender::QCamera *camera = view.camera();
camera->lens()->setPerspectiveProjection(1000.0f, 16.0f/9.0f, 0.1f, 1000.0f);
camera->setPosition(QVector3D(-500, -100, 40.0f));
camera->setViewCenter(QVector3D(0, 0, 0));

Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity);
Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity);
light->setColor("white");
light->setIntensity(0.8f);
lightEntity->addComponent(light);

Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity);
lightTransform->setTranslation(QVector3D(60, 0, 40.0f));
lightEntity->addComponent(lightTransform);

Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController(rootEntity);

camController->setCamera(camera);
camController->setLinearSpeed( 5000.0f );
camController->setLookSpeed( 1000.0f );
view.setRootEntity(rootEntity);
view.show();

1 个答案:

答案 0 :(得分:0)

您可以为3D窗口创建容器。此容器是QWidget,您可以将其嵌入到布局的其余部分中。

QWidget *container = QWidget::createWindowContainer(3DWindow);
widgetLayout->addWidget(container);

当然,你必须在3D窗口中省略view.show();,但在主窗口上调用它。