Hello!

I am trying to implement a "warp mouse" effect (the mouse cursor stays in the same spot on my widget even when mouse is moving) by using QCursor::setPos but it has no effect.

Qt Code:
  1. void QmlMouseController::warpMouse(const QPoint & p)
  2. {
  3. std::cout << "pre pos: " << QCursor::pos(0).x() << " " << QCursor::pos(0).y() << std::endl;
  4. std::cout << "warp: " << p.x() << " " << p.y() << std::endl;
  5. QCursor::setPos(QApplication::primaryScreen() ,p);
  6. std::cout << "post pos: " << QCursor::pos(0).x() << " " << QCursor::pos(0).y() << std::endl;
  7. }
To copy to clipboard, switch view to plain text mode 

When the above code is called with a QPoint that holds the mouse coordinates that i want to move the cursor to it prints:

Qt Code:
  1. pre pos: -2147483648 -2147483648
  2. warp: 799 361
  3. post pos: -2147483648 -2147483648
To copy to clipboard, switch view to plain text mode 

QCursor:: pos returns -2147483648 and setPos has no effect ?! (all versions of setPos has been tested)
I am calling this function from QML but i dont think that should matter.

Running Windows 10 and Qt 5.12

Any help and ideas are appreciated.

Br
--Anders