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. Displaying a View3D QML type in QQuickWidget looses input interaction
QtWS25 Last Chance

Displaying a View3D QML type in QQuickWidget looses input interaction

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 222 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.
  • D Offline
    D Offline
    dominion
    wrote on last edited by
    #1

    Greetings.

    I am in the process of wanting to try and migrate the display of the 3D graphics of an application I have put together from a qt QOpenGLWidget to using a QQuickWidget using a QML script. I am new to QML, but I find it really easy to understand and use, but have found that QML is not that reliable to use as some code does not work under different circumstances to the examples given.

    In my testing I have succeeded in displaying 3D graphics and importing some custom geometry using QQuickWidget as a basis of running QML scripts. But If I do not use a QML window or applicationwindow type as the means of displaying the 3D graphics, I loose the ability to interact with the scene camera through using the keyboard and mouse.

    The QML code I am using is of form

    import QtQuick
    import QtQuick3D
    import QtQuick.Controls
    import Qt.labs.platform // required for ApplicationWindow to be displayed
    
    import QtQuick3D.Helpers
    
    import CustomGeometry 1.0
    
    Item {
      
       Window{
       //ApplicationWindow{
        
        id: window
        width: 1280
        height: 720
        visible: true
        //color: "#848895"
        color: "#000000"
        flags : Qt.Widget
    
        View3D {
            anchors.fill: parent
    
            environment : SceneEnvironment {
                lightProbe: Texture{
                    source: "qt_logo.png"
                }
            }
    
            camera: camera
    
            PerspectiveCamera {
                id: camera
                position: Qt.vector3d(0, 200, 300)
                eulerRotation.x: -30
           }
           < Display code>
    
            Keys.onPressed: {
               if (event.key == Qt.Key_Left) {
                    camera.x = camera.x-10;
               }
    
               if (event.key == Qt.Key_Right) {
                    camera.x = camera.x+10;
               }
            }
    
        } //View3D 
    
        WasdController { // usual default wasd key and mouse controller
            controlledObject: camera // set camera to be controlled by wasd keys + mouse
                                     // Potential bug :- Loose ability to selects GUI widgets
            mouseEnabled : true;
        }
    
    } // Window
    }
    

    Which will display the graphics within a window outside the QQuickWidget that can have keyboard and mouse control over the position and orientation of the 3D camera via the WasdController and Keys.onPressed code.

    If I comment out the window QML type, I get the same 3D view displayed within the QQuickWidget itself as prefered, but now there is no keyboard or mouse control over the position and orientation of the 3D camera. If I try and use the window type as a root to the QQuickWidget by commenting out the Item type , I get an error message.

    So my question is,

    A : is there a way to embed the QML window type to have the QQuickWidget as a kind of parent similar to a Qt Widget being parented to any other Qt Widget so as to retain what ever a QML window type has to enable mouse and keyboard interaction? It seems from the error messages I get, a QML window type cannot be parented.

    B: Is there something that I am missing that needs to be included in the QML item type, or another QML type that needs to be used to allow this interaction to occur?

    I have spent hours looking at the documentation and examples and found nothing of any help.
    If any one here can help me with this, it will be much appreciated. Thanks

    Dominion.

    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