Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. [SOLVED]glutMouseMotion in QGLWidget

[SOLVED]glutMouseMotion in QGLWidget

Scheduled Pinned Locked Moved Game Development
5 Posts 2 Posters 5.4k 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.
  • S Offline
    S Offline
    Sapidol2002
    wrote on last edited by
    #1

    hi..

    I want to track mouse motion like GLUT Function Callback : glutMotionFunc
    so it will return mouse in relative position

    how can I use that glutMotionFunc in QGLWidget
    or there is another way to track with mouseMoveEvent ?

    Thanks...

    1 Reply Last reply
    0
    • M Offline
      M Offline
      minimoog77
      wrote on last edited by
      #2

      You must handle, like you sad, http://doc.qt.nokia.com/latest/qwidget.html#mouseMoveEvent .

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sapidol2002
        wrote on last edited by
        #3

        Thank you for reply

        I Already handle mouseMoveEvent in my QGLWidget let say it MyGLClass

        MyGLClass.h
        @
        class MyGLClass : public QGLWidget
        {
        Q_OBJECT
        private:
        int old_x;
        int old_y;
        void mouseMotion(int x, int y);
        ...
        protected:
        void mousePressEvent(QMouseEvent *event);
        ...
        }
        @

        MyGLClass.cpp
        @
        ....
        void MyGLClass::mouseMoveEvent ( QMouseEvent * event )
        {
        int motionX = event->x() - old_x;
        int motionY = event->y() - old_y;
        mouseMotion(motionX, motionY);

            old_x = event->x();
            old_y = event->y();
        

        }
        void MyGLClass::mouseMotion(int x, int y)
        {
        // this function receive mouse in relative position
        // e.g. :
        // when you move move your mouse left
        // x will be -1 ( or -6 ) depends of your speed when move your mouse
        }
        ...
        @

        the problem is the function mouseMotion receive zero value when mouse reach the edge of the screen
        because the delta of before and after of mouse position is zero

        I want to keep track the mouse relative position even if in the edge of the screen
        like glutMotionFunc or DirectInput does

        Thanks, sorry for my english..

        1 Reply Last reply
        0
        • M Offline
          M Offline
          minimoog77
          wrote on last edited by
          #4

          Well I was using neat trick, I don't know if this could be apply to QGLWidget...

          When there is move on the mouse pointer, calculate delta, and then return mouse pointer to center of the widget. Simple. But the problem is that you need to hide the mouse pointer...

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sapidol2002
            wrote on last edited by
            #5

            thanks that trick work for QGLWidget also..

            Thank you..

            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