#include #include #include #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char* argv[]) { QApplication a(argc, argv); auto view = new Qt3DExtras::Qt3DWindow(); auto renderSettings = view->renderSettings(); renderSettings->setRenderPolicy(Qt3DRender::QRenderSettings::Always); auto rootEntity = new Qt3DCore::QEntity(); view->setRootEntity(rootEntity); auto camera = view->camera(); camera->lens()->setPerspectiveProjection(45.0f, 1., 0.1f, 10000.0f); camera->setPosition(QVector3D(0, 0, 5)); camera->setUpVector(QVector3D(0, 1, 0)); camera->setViewCenter(QVector3D(0, 0, 0)); auto camController = new Qt3DExtras::QOrbitCameraController(rootEntity); camController->setCamera(camera); auto pointSize = 15.f; auto text = QString::fromLatin1("ValidString"); auto emptyText = QString::fromLatin1(""); auto anotherText = QString::fromLatin1("Arial"); QFont font; font.setFamily("Arial"); font.setPointSizeF(pointSize); auto sampleTextEntity = new Qt3DCore::QEntity(rootEntity); auto textMesh = new Qt3DExtras::QText2DEntity(/*sampleTextEntity*/); textMesh->setParent(sampleTextEntity); textMesh->setFont(font); textMesh->setColor(Qt::black); QFontMetricsF fontMetrics(textMesh->font()); auto boundingRect = fontMetrics.boundingRect(QRectF(), Qt::AlignLeft | Qt::AlignTop, text); textMesh->setWidth(boundingRect.width()); textMesh->setHeight(boundingRect.height()); textMesh->setText(text); auto container = QWidget::createWindowContainer(view); QFrame frame; frame.setLayout(new QVBoxLayout); frame.layout()->addWidget(container); frame.resize(QSize(400, 300)); QTimer::singleShot(100, [&]() { camera->viewAll(); }); QTimer::singleShot(3000, [&]() { textMesh->setText(emptyText); }); QTimer::singleShot(4000, [&]() { textMesh->setText(anotherText); }); frame.show(); return a.exec(); }