Important: Please read the Qt Code of Conduct -

How to rotate 3d models rendered in Qt5.7?

  • Hi All,

    I am a newbie in Qt. Learning and exploring, I came across a sample application to load 3d models following the assimp-cpp sample in Qt5.7.
    Previously, using the Qt5.6 version, I could load the model and could rotate it by (rt-mouse-click + drag) and move it by (left-mouse-click + drag).

    However, I see that I am just able to move the model in 5.7 version.
    How can I make it rotate as well.
    Here is the snippet as in assimp-cpp,

    int main(int ac, char **av)
        QApplication app(ac, av);
        Qt3DExtras::Qt3DWindow view;
        // Root entity
        Qt3DCore::QEntity *sceneRoot = new Qt3DCore::QEntity();
        // Scene Camera
        Qt3DRender::QCamera *camera =;
        camera->setAspectRatio(view.width() / view.height());
        camera->setUpVector(QVector3D(0.0f, 1.0f, 0.0f));
        camera->setViewCenter(QVector3D(0.0f, 1.1f, 0.0f));
        camera->setPosition(QVector3D(0.0f, 2.5f, 2.0f));
        // For camera controls
        Qt3DExtras::QFirstPersonCameraController *camController = new Qt3DExtras::QFirstPersonCameraController(sceneRoot);
        // Scene loader
        Qt3DCore::QEntity *sceneLoaderEntity = new Qt3DCore::QEntity(sceneRoot);
        Qt3DRender::QSceneLoader *sceneLoader = new Qt3DRender::QSceneLoader(sceneLoaderEntity);
        SceneWalker sceneWalker(sceneLoader);
        QObject::connect(sceneLoader, &Qt3DRender::QSceneLoader::statusChanged, &sceneWalker, &SceneWalker::onStatusChanged);
        QStringList args = QCoreApplication::arguments();
        QUrl sourceFileName;
        if (args.count() <= 1) {
            QWidget *container = new QWidget();
            QFileDialog dialog;
            sourceFileName = dialog.getOpenFileUrl(container, QStringLiteral("Open a scene file"));
        } else {
            sourceFileName = QUrl::fromLocalFile(args[1]);
        if (sourceFileName.isEmpty())
            return 0;
        return app.exec();

    Anything I can add here?

  • You will probably have to replace QFirstPersonCameraController by QOrbitCameraController.

  • @m.sue
    That did the trick!!
    Thanks a tonne!!!

Log in to reply