[英]add STL file to a QT Widget
I'm trying to create a viewer for STL files with QT5.10 and c++. 我正在尝试使用QT5.10和c ++创建STL文件的查看器。 I suceeded to view the file in a
QWindow
but I didn't find how to view it in a QWidget
. 我想在
QWindow
查看文件,但没有找到如何在QWidget
查看文件。 This is what i want to do Qt Designer . 这就是我要做的Qt Designer 。
This is the code for viewing it in a QWindow
: 这是用于在
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();
You can create a container for your 3D window. 您可以为3D窗口创建一个容器。 This container is a
QWidget
which you can then embed in the rest of your layout. 这个容器是一个
QWidget
,您可以将其嵌入其余的布局中。
QWidget *container = QWidget::createWindowContainer(3DWindow);
widgetLayout->addWidget(container);
Of course you have to omit view.show();
当然,您必须省略
view.show();
on the 3D window but call this on your main window. 在3D窗口中,但在主窗口中调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.