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

1st November 2014, 21: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.

4th November 2014, 08:45
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,