Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Send QKeyEvent to QOrbitCameraController



  • I'm using QOrbitCameraController as the camera controller for displaying a QMesh. QOrbitCameraController allows users to press the escape key in order to display all of the mesh inside of its viewing window. In my case, this is a QWidget created from a Qt3DWindow.

    Is there a way to send an escape key event to the camera controller so that it displays the initial view just as if the escape key had been pressed. I've tried postEvent and sendEvent, but there is no change in the view of the mesh. Anyone have any clues?

    Qt3DExtras::QOrbitCameraController *cameraController = new Qt3DExtras::QOrbitCameraController(rootScene);
    QCoreApplication::postEvent(cameraController, new QKeyEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier));
    


  • Thanks for your input. I did not see anything in the QOrbitCameraController hierarchy that provided any clues related to the QKeyEvent; however, it seems that I overlooked the obvious as I drove straight into the weeds. QCamera provides the capability to view the entire model via its viewAll() method. The code snippet follows.

    Qt3DExtras::Qt3DWindow *view3DWindow = new Qt3DExtras::Qt3DWindow();
    view3DWindow->setRootEntity(rootScene);
    QWidget *view3DWidget = QWidget::createWindowContainer(view3DWindow);
    Qt3DRender::QCamera *camera = view3DWindow->camera();
    Qt3DExtras::QOrbitCameraController *cameraController = new Qt3DExtras::QOrbitCameraController(rootScene);
    cameraController->setCamera(camera);
    view3DWidget->show();
    camera->viewAll();
    


  • I think you are on the right path here, but as just a WAG, perhaps the key event handler within QOrbitCamerController is in a subclass there-of, and not being directly interpretted by the main class. That would be my guess as to the reason passing the key event is ignored.



  • Thanks for your input. I did not see anything in the QOrbitCameraController hierarchy that provided any clues related to the QKeyEvent; however, it seems that I overlooked the obvious as I drove straight into the weeds. QCamera provides the capability to view the entire model via its viewAll() method. The code snippet follows.

    Qt3DExtras::Qt3DWindow *view3DWindow = new Qt3DExtras::Qt3DWindow();
    view3DWindow->setRootEntity(rootScene);
    QWidget *view3DWidget = QWidget::createWindowContainer(view3DWindow);
    Qt3DRender::QCamera *camera = view3DWindow->camera();
    Qt3DExtras::QOrbitCameraController *cameraController = new Qt3DExtras::QOrbitCameraController(rootScene);
    cameraController->setCamera(camera);
    view3DWidget->show();
    camera->viewAll();
    

Log in to reply