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.
void QmlMouseController
::warpMouse(const QPoint & p
) {
std
::cout <<
"pre pos: " <<
QCursor::pos(0).
x() <<
" " <<
QCursor::pos(0).
y() << std
::endl;
std::cout << "warp: " << p.x() << " " << p.y() << std::endl;
std
::cout <<
"post pos: " <<
QCursor::pos(0).
x() <<
" " <<
QCursor::pos(0).
y() << std
::endl;
}
void QmlMouseController::warpMouse(const QPoint & p)
{
std::cout << "pre pos: " << QCursor::pos(0).x() << " " << QCursor::pos(0).y() << std::endl;
std::cout << "warp: " << p.x() << " " << p.y() << std::endl;
QCursor::setPos(QApplication::primaryScreen() ,p);
std::cout << "post pos: " << QCursor::pos(0).x() << " " << QCursor::pos(0).y() << std::endl;
}
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:
pre pos: -2147483648 -2147483648
warp: 799 361
post pos: -2147483648 -2147483648
pre pos: -2147483648 -2147483648
warp: 799 361
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
Bookmarks