Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to override mouse controls for the QOrbitCameraController class?
Forum Update on Monday, May 27th 2025

How to override mouse controls for the QOrbitCameraController class?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qorbitcameraqt5.7mouseevent
6 Posts 4 Posters 2.6k 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.
  • PoortiP Offline
    PoortiP Offline
    Poorti
    wrote on last edited by Poorti
    #1

    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.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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;
      
      1 Reply Last reply
      1
      • PoortiP Offline
        PoortiP Offline
        Poorti
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • m.sueM Offline
          m.sueM Offline
          m.sue
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          3
          • PoortiP Offline
            PoortiP Offline
            Poorti
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SiE_JET
              wrote on last edited by
              #6

              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

              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