Results 1 to 2 of 2

Thread: Force Mouse/Cursor to move only Horizontally or Vertically

  1. #1
    Join Date
    Nov 2014
    Posts
    1
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Windows

    Question Force Mouse/Cursor to move only Horizontally or Vertically

    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.

  2. #2
    Join Date
    Nov 2006
    Location
    indonesia
    Posts
    55
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Force Mouse/Cursor to move only Horizontally or Vertically

    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

Similar Threads

  1. Replies: 3
    Last Post: 22nd February 2013, 19:56
  2. how to use Qcursor to move the mouse cursor
    By jack_shen in forum Newbie
    Replies: 3
    Last Post: 22nd March 2010, 07:20
  3. Validator: force keeping cursor back in widget
    By antarctic in forum Qt Programming
    Replies: 1
    Last Post: 8th June 2009, 14:15
  4. can't move cursor
    By felix_tang in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2009, 09:36
  5. how to add QAction vertically and horizontally in QToolBar
    By sanjayshelke in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2008, 09:56

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.