QCursor::setPos has no effect
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.
Code:
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;
}
When the above code is called with a QPoint that holds the mouse coordinates that i want to move the cursor to it prints:
Code:
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
Re: QCursor::setPos has no effect
What if you pass a valid screen pointer to pos() instead of a null pointer. Or call the pos() overload without arguments?
Cheers,
_
Re: QCursor::setPos has no effect
Good catch :) However it makes no difference with any other version of pos()
Br
--Anders
Re: QCursor::setPos has no effect
https://doc.qt.io/qt-5/qcursor.html#setPos-1
"Note: On platforms where there is no windowing system or cursors are not available, this function may do nothing."
Now the question is if windows falls in this category