PDA

View Full Version : Force Mouse/Cursor to move only Horizontally or Vertically



Devower
1st November 2014, 22:34
I'm trying to figure out a way to make the mouse/cursor be restricted to either moving only vertically or horizontally (along either the y or x axis). I understand that there is the QCursor::setPos that can give it a location, but I haven't been able to figure out how (if possible) to only move along one axis. My end goal is to be able to move the cursor in a perfectly straight horizontal or vertical fashion. I am handling this logic in a mouseMoveEvent so that when the shift button is held down, it forces this behavior.

Thank you.

myta212
4th November 2014, 09:45
Hi,
You can get mouse position using mouseevent method. Example, if you want to move your mouse cursor along X axis, save your Y mouse position (YPOS)
So, when you change your mouse position, change your cursor position Y by YPOS. Same method if you want to move your mouse by Y axis.

Best regards,

myta