How to override mouse controls for the QOrbitCameraController class?



  • Hi All,

    I am using QOrbitCameraController class to set camera controls for my Qt3DWindow.
    The current workflow of the mouse is such,

    QOrbitCameraController controls

    I want to change this such that the right mouse button functionality is triggered on the left mouse button press.

    I tried setting event listeners for the this class, but wasn't sure how to proceed.
    Here is the code snippet where I use the class,

    // Scene Camera
    Qt3DRender::QCamera *camera = view.camera();
    camera->setProjectionType(Qt3DRender::QCameraLens::PerspectiveProjection);
    camera->setAspectRatio(view.width() / view.height());
    camera->setUpVector(QVector3D(0.0f, 1.0f, 0.0f));
    camera->setViewCenter(QVector3D(0.04f, 1.0f, 0.0f));
    camera->setPosition(QVector3D(0.0f, 2.5f, 2.1f));
    camera->setNearPlane(0.001f);
    camera->setFarPlane(100.0f);
    
    // For camera controls
    Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController(sceneRoot);
    camController->setCamera(camera);
    

    Is there any way I can do that?
    Please guide me.
    I am using Qt 5.7 on windows.


  • Lifetime Qt Champion

    Hi
    I dont think you can.
    The actual mouse function seems to be hidden away in some PRIVATE file so it leaves no room for subclassing and override.
    I dont know is there is a way to set them via interface.
    It seems if we could swap
    Qt3DInput::QAction *m_leftMouseButtonAction;
    Qt3DInput::QAction *m_rightMouseButtonAction;
    that would be it.

    class QOrbitCameraControllerPrivate : public Qt3DCore::QEntityPrivate
    {
    public:
        QOrbitCameraControllerPrivate();
    
        void init();
    
        Qt3DRender::QCamera *m_camera;
    
        Qt3DInput::QAction *m_leftMouseButtonAction;
        Qt3DInput::QAction *m_rightMouseButtonAction;
        Qt3DInput::QAction *m_altButtonAction;
        Qt3DInput::QAction *m_shiftButtonAction;
    


  • But if it's private, then it won't be accessible to the application.
    The default behavior of the camera will not be popular with the users if used in a product. And if there is no way to override it, are we stuck with this?

    I wonder why they did it like this.



  • Hi,
    The only way to do this is to copy the code of the class and do what you want there.
    The problem you will have with almost all of the classes in the Qt3DExtras namespace. They seem not to be designed to be expandible or even to derive from them. I think they are just there to make the Qt3D cpp-examples look easy and short but their code should be in fact counted as part of the examples.
    -Michael.



  • Any way we can atleast block the actions of a mouse click event?
    For eg, block the left click and move.. so that user can't move the camera left, right or up, down?



  • I know, quite a bit old. But it took me a long time to find the right solution...
    Take a look at this:
    stack overflow : My Qt eventFilter() doesn't stop events as it should
    It does the trick for me.
    -JET