Androiders
25th March 2019, 08:48
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;
QCursor::setPos(QApplication::primaryScreen() ,p);
std::cout << "post pos: " << QCursor::pos(0).x() << " " << QCursor::pos(0).y() << std::endl;
}
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
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
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;
QCursor::setPos(QApplication::primaryScreen() ,p);
std::cout << "post pos: " << QCursor::pos(0).x() << " " << QCursor::pos(0).y() << std::endl;
}
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
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