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. Mouse controls over Qt 3D Window
Qt 6.11 is out! See what's new in the release blog

Mouse controls over Qt 3D Window

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 2.9k Views 2 Watching
  • 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
    dsell002
    wrote on last edited by
    #1

    I have a QWidget containing a Qt3DWindow(). I'd like to be able to "zoom" in and out on a QtEntity, within the Qt3DWindow, using the mouse scroll wheel, while hovering over the window.

    I have the functionality working, but only when hovering the mouse outside of the Qt3DWindow frame. Here's my code for initializing the window and processing mouse wheel events.

    Window Initialization:

    mainView = new Qt3DExtras::Qt3DWindow();
    mainView->defaultFramegraph()->setClearColor(QColor(QRgb(0x4d4d4f)));
    
    QWidget *container = QWidget::createWindowContainer(mainView);
    

    Processing wheel events:

    void ModelView::wheelEvent(QWheelEvent *event){
    
        QVector3D vec;
    
        vec = cameraEntity->position() - modifier->m_transform->translation();
    
        vec = vec.normalized();
    
        QPoint delta = event->angleDelta();
    
        int zoom_distance = delta.y()*0.01;
    
        vec = cameraEntity->position() - zoom_distance*vec;
    
        cameraEntity->setPosition(vec);
    }
    

    What's the trick for overriding the window's mouse grab when hovering over the Qt3DWindow frame?

    Thanks in advance for any help.

    kshegunovK 1 Reply Last reply
    0
    • D dsell002

      I have a QWidget containing a Qt3DWindow(). I'd like to be able to "zoom" in and out on a QtEntity, within the Qt3DWindow, using the mouse scroll wheel, while hovering over the window.

      I have the functionality working, but only when hovering the mouse outside of the Qt3DWindow frame. Here's my code for initializing the window and processing mouse wheel events.

      Window Initialization:

      mainView = new Qt3DExtras::Qt3DWindow();
      mainView->defaultFramegraph()->setClearColor(QColor(QRgb(0x4d4d4f)));
      
      QWidget *container = QWidget::createWindowContainer(mainView);
      

      Processing wheel events:

      void ModelView::wheelEvent(QWheelEvent *event){
      
          QVector3D vec;
      
          vec = cameraEntity->position() - modifier->m_transform->translation();
      
          vec = vec.normalized();
      
          QPoint delta = event->angleDelta();
      
          int zoom_distance = delta.y()*0.01;
      
          vec = cameraEntity->position() - zoom_distance*vec;
      
          cameraEntity->setPosition(vec);
      }
      

      What's the trick for overriding the window's mouse grab when hovering over the Qt3DWindow frame?

      Thanks in advance for any help.

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

      You need a mouse controller in Qt3D, not an override of the view's mouse handling routines. Take a look at the Qt3DInput's module docs, for example here's a place to start.

      Read and abide by the Qt Code of Conduct

      D 1 Reply Last reply
      0
      • kshegunovK kshegunov

        You need a mouse controller in Qt3D, not an override of the view's mouse handling routines. Take a look at the Qt3DInput's module docs, for example here's a place to start.

        D Offline
        D Offline
        dsell002
        wrote on last edited by
        #3

        @kshegunov I ended up using an event filter to catch the mouse wheel events over the window.

            mainView = new Qt3DExtras::Qt3DWindow();
            mainView->defaultFramegraph()->setClearColor(QColor(QRgb(0x4d4d4f)));
        
            mainView->installEventFilter(this);
        
        bool ModelView::eventFilter(QObject *obj, QEvent *event)
        {
            switch(event->type())
            {
            case QEvent::KeyPress:
            {
                QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
                return true;
            }
                break;
            case QEvent::Wheel:
            {
                QWheelEvent *wheelEvent = static_cast<QWheelEvent *>(event);
        
                QVector3D vec;
        
                vec = cameraEntity->position() - modifier->m_transform->translation();
        
                vec = vec.normalized();
        
                QPoint delta = wheelEvent->angleDelta();
        
                int zoom_distance = delta.y()*0.01;
        
                vec = cameraEntity->position() - zoom_distance*vec;
        
                cameraEntity->setPosition(vec);
                return true;
            }
                break;
            default:
                // standard event processing
                return QObject::eventFilter(obj, event);
                break;
        
            }
        
        }
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          Saitodepaula
          wrote on last edited by
          #4

          I've posted a similar question here: https://forum.qt.io/topic/92804/simplest-way-to-get-mouse-events-on-qt3dwindow

          Could any of you help?

          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