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. Mouse lock inside window/widget

Mouse lock inside window/widget

Scheduled Pinned Locked Moved Game Development
4 Posts 3 Posters 5.8k Views 1 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.
  • C Offline
    C Offline
    carbiii
    wrote on last edited by
    #1

    I am trying to stop the mouse from leaving the window. This is useful for first person cameras in OpenGL, as well as full screen mouse-heavy games with multiple monitors. I mostly am just looking to keep it inside the window, however keeping the mouse inside a widget could also be useful to know.

    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      Ymalaika
      wrote on last edited by
      #2

      You can move the mouse cursor using QCursor::setPos( int x, int y );

      http://qt-project.org/doc/qt-4.8/qcursor.html#setPos

      1 Reply Last reply
      0
      • U Offline
        U Offline
        utcenter
        wrote on last edited by
        #3

        Why don't you just restrain the cursor to the dead center of your game window while the FPS game is running, and only release it when you open some menu and interrupt the game? It will still be useful to be able to leave your window while the game is interrupted.

        But if that is what you want to achieve, you can use the mouse leave event to restrain the cursor to its last position that was inside of the window, obviously you will have to track that.

        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          Ymalaika
          wrote on last edited by
          #4

          Yes, What utcenter said. I've created FPS-like interaction in a QGLWidget, and using the restrain to dead-center approach worked best for me. If you let the cursor get too close to the edge, rapid subsequent mouse movements can leave the frame, resulting in sometimes missing mousemove events. And you want to avoid things like using grabMouse() to get around that if at all possible.

          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