Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-74971

mouse events contain incorrect position when using QCursor::setPos

    XMLWordPrintable

Details

    • macOS, Windows

    Description

      Introduction

      Sometimes it's necessary to move the mouse further than allowed by the bounds of the screen:

      Imagine a slider that uses the downscaled mouse movement to allow fine adjustments. When that slider is close to the edge of the screen, the movement of the cursor can be blocked.

      A common solution is to "freeze" the cursor at the pressed position while the slider is moved. This is implemented by returning the cursor to the frozen position in the mouseMoveEvent handler using QCuror::setPos. (This causes unpleasant jumps of the cursor, so it gets hidden.)

       

      Description

      When the cursor is moved in the mouseMoveEvent handler using QCursor::setPos, QMouseEvent::localPos / QHoverEvent::posF and QCursor::pos may differ:

      • build the attached project
      • quickly press, move and release the mouse on either of the two rectangles
      • the red rectangle logs mismatched positions in the mouseMoveEvent handler
      • the green rectangle logs mismatched positions in the mouseHoverMove event handler

      possible output:

      mouseMoveEvent, positions differ:
        event : QPointF(134,216) 
        cursor: QPointF(137,232)
      hoverMoveEvent, positions differ:
        event : QPointF(90,161) 
        cursor: QPointF(89,166)
      

       

       

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              srutledg Shawn Rutledge
              tobiasludwig Tobias Ludwig
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes