Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Is it possible to embbed a 3dscene in qml Pane (Qt.QuickControl) type?
Forum Update on Monday, May 27th 2025

Is it possible to embbed a 3dscene in qml Pane (Qt.QuickControl) type?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qt3dqtquickqtquickcontrols
4 Posts 2 Posters 696 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    ItzMeJP
    wrote on last edited by ItzMeJP
    #1

    I am programming a graphical interface that I need to include a small 3DWindow inside a Pane type from Qt QuickControl.

    Thus, I did the follwoing:

    import QtQuick 2.4
    import QtQuick.Controls 2.15
    import Qt3D.Core 2.0
    import Qt3D.Render 2.0
    import Qt3D.Input 2.0
    import Qt3D.Extras 2.0
    import QtQuick.Scene3D 2.0
    
    Page {
    
        property alias _width_param: home_page.width
        property alias _height_param: home_page.height
    
        id: home_page
        title: "Home"
        transformOrigin: Item.Center
    
        header: Label {
            id: title_label
            text: home_page.title
            horizontalAlignment: Text.AlignLeft
            verticalAlignment: Text.AlignVCenter
            font.weight: Font.Normal
        }
    
        Scene3D {
            id: scene3d
    
            anchors.fill: parent
            focus: true
            cameraAspectRatioMode: Scene3D.AutomaticAspectRatio
            aspects: ["input", "logic"]
    
             MyViewer {
                 id: my
                 aspectRatio: home_page.width / home_page.height
             }
        }
    }
    

    which MyViewer is defined in MyViewer.qml

    
    import QtQuick 2.4
    import Qt3D.Core 2.0
    import Qt3D.Render 2.0
    import Qt3D.Input 2.0
    import Qt3D.Extras 2.0
    import QtQuick.Scene3D 2.0
    import QtQuick.Controls 2.15
    
    Entity {
        id: entity_root
    
        property alias aspectRatio: mainCamera.aspectRatio
    
        // Render from the mainCamera
        components: [
            RenderSettings {
                activeFrameGraph: ForwardRenderer {
                    id: renderer
                    camera: mainCamera
                }
            },
            // Event Source will be set by the Qt3DQuickWindow
            InputSettings { }
        ]
    
        Camera {
            id: mainCamera
    
            projectionType: CameraLens.PerspectiveProjection
            fieldOfView: 22.5
            //aspectRatio: _window.width / _window.height
            nearPlane:   0.01
            farPlane:    1000.0
            viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
            upVector:   Qt.vector3d( 0.0, 1.0, 0.0 )
        }
    
        FirstPersonCameraController { camera: mainCamera }
    
        PhongMaterial {
            id: material
        }
    
        Mesh{
            id:objMesh
            //source:"obj.ply"
            source:"file://home/joaopedro/qt_ws/qml3DExample/obj.ply"
        }
    
        Transform {
            id: objTransform
            scale3D: Qt.vector3d(10, 10, 10)
            rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45)
        }
    
        Entity {
            id: objEntity
            components: [ objMesh, material, objTransform ]
        }
    }
    
    

    However the 3DScene is not plotting anything. Anyone can help me with that?

    kshegunovK 1 Reply Last reply
    0
    • I ItzMeJP

      I am programming a graphical interface that I need to include a small 3DWindow inside a Pane type from Qt QuickControl.

      Thus, I did the follwoing:

      import QtQuick 2.4
      import QtQuick.Controls 2.15
      import Qt3D.Core 2.0
      import Qt3D.Render 2.0
      import Qt3D.Input 2.0
      import Qt3D.Extras 2.0
      import QtQuick.Scene3D 2.0
      
      Page {
      
          property alias _width_param: home_page.width
          property alias _height_param: home_page.height
      
          id: home_page
          title: "Home"
          transformOrigin: Item.Center
      
          header: Label {
              id: title_label
              text: home_page.title
              horizontalAlignment: Text.AlignLeft
              verticalAlignment: Text.AlignVCenter
              font.weight: Font.Normal
          }
      
          Scene3D {
              id: scene3d
      
              anchors.fill: parent
              focus: true
              cameraAspectRatioMode: Scene3D.AutomaticAspectRatio
              aspects: ["input", "logic"]
      
               MyViewer {
                   id: my
                   aspectRatio: home_page.width / home_page.height
               }
          }
      }
      

      which MyViewer is defined in MyViewer.qml

      
      import QtQuick 2.4
      import Qt3D.Core 2.0
      import Qt3D.Render 2.0
      import Qt3D.Input 2.0
      import Qt3D.Extras 2.0
      import QtQuick.Scene3D 2.0
      import QtQuick.Controls 2.15
      
      Entity {
          id: entity_root
      
          property alias aspectRatio: mainCamera.aspectRatio
      
          // Render from the mainCamera
          components: [
              RenderSettings {
                  activeFrameGraph: ForwardRenderer {
                      id: renderer
                      camera: mainCamera
                  }
              },
              // Event Source will be set by the Qt3DQuickWindow
              InputSettings { }
          ]
      
          Camera {
              id: mainCamera
      
              projectionType: CameraLens.PerspectiveProjection
              fieldOfView: 22.5
              //aspectRatio: _window.width / _window.height
              nearPlane:   0.01
              farPlane:    1000.0
              viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
              upVector:   Qt.vector3d( 0.0, 1.0, 0.0 )
          }
      
          FirstPersonCameraController { camera: mainCamera }
      
          PhongMaterial {
              id: material
          }
      
          Mesh{
              id:objMesh
              //source:"obj.ply"
              source:"file://home/joaopedro/qt_ws/qml3DExample/obj.ply"
          }
      
          Transform {
              id: objTransform
              scale3D: Qt.vector3d(10, 10, 10)
              rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45)
          }
      
          Entity {
              id: objEntity
              components: [ objMesh, material, objTransform ]
          }
      }
      
      

      However the 3DScene is not plotting anything. Anyone can help me with that?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @ItzMeJP said in Is it possible to embbed a 3dscene in qml Pane (Qt.QuickControl) type?:

      However the 3DScene is not plotting anything. Anyone can help me with that?

      You haven't set the root entity of the scene.

      Scene3D  {
          ...
          entity: MyViewer  {
              ...
          }
      }
      

      should do it.

      Read and abide by the Qt Code of Conduct

      I 1 Reply Last reply
      0
      • kshegunovK kshegunov

        @ItzMeJP said in Is it possible to embbed a 3dscene in qml Pane (Qt.QuickControl) type?:

        However the 3DScene is not plotting anything. Anyone can help me with that?

        You haven't set the root entity of the scene.

        Scene3D  {
            ...
            entity: MyViewer  {
                ...
            }
        }
        

        should do it.

        I Offline
        I Offline
        ItzMeJP
        wrote on last edited by
        #3

        @kshegunov said in Is it possible to embbed a 3dscene in qml Pane (Qt.QuickControl) type?:

        entity:

        thank you, but it still crash my application. Is there any problem regarding my main.cpp code?

        #include <QGuiApplication>
        #include <QQmlApplicationEngine>
        
        int main(int argc, char *argv[])
        {
        #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
            QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        #endif
        
            QGuiApplication app(argc, argv);
        
            QQmlApplicationEngine engine;
            const QUrl url(QStringLiteral("qrc:/main.qml"));
            QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                             &app, [url](QObject *obj, const QUrl &objUrl) {
                if (!obj && url == objUrl)
                    QCoreApplication::exit(-1);
            }, Qt::QueuedConnection);
            engine.load(url);
        
            return app.exec();
        }
        
        
        kshegunovK 1 Reply Last reply
        0
        • I ItzMeJP

          @kshegunov said in Is it possible to embbed a 3dscene in qml Pane (Qt.QuickControl) type?:

          entity:

          thank you, but it still crash my application. Is there any problem regarding my main.cpp code?

          #include <QGuiApplication>
          #include <QQmlApplicationEngine>
          
          int main(int argc, char *argv[])
          {
          #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
              QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
          #endif
          
              QGuiApplication app(argc, argv);
          
              QQmlApplicationEngine engine;
              const QUrl url(QStringLiteral("qrc:/main.qml"));
              QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                               &app, [url](QObject *obj, const QUrl &objUrl) {
                  if (!obj && url == objUrl)
                      QCoreApplication::exit(-1);
              }, Qt::QueuedConnection);
              engine.load(url);
          
              return app.exec();
          }
          
          
          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @ItzMeJP said in Is it possible to embbed a 3dscene in qml Pane (Qt.QuickControl) type?:

          thank you, but it still crash my application.

          What crash? You never said anything about a crash ...

          Is there any problem regarding my main.cpp code?

          Not that I can see.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved