Results 1 to 2 of 2

Thread: Lock Mouse Image Position

  1. #1
    Join Date
    Feb 2014
    Posts
    23
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Lock Mouse Image Position

    Hi All!

    I am changing my mouse cursor to an image that the user can place onto different spots of my scene. I have the place-able locations laid out into a grid of squares, so what I would like to do is restrict the movement of the mouse cursor image to the exact grid square that it would be placed within if clicked at any moment.

    I'm almost positive this will involve creating an override of the QCursor class, but I can't really figure out how to get started based upon the documentation.

    From my readings, I don't believe that changing the hotspot would hold the image still as I think it just changes what part of the image is received as the "click location".

    Perhaps temporarily drop the mouse cursor onto the scene, make the mouse have no cursor, and either restore the image to the mouse when it leaves a grid location, or restore the typical pointer upon a click?

    Any advice would be helpful, thanks.

  2. #2
    Join Date
    Feb 2014
    Posts
    23
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Lock Mouse Image Position

    Well if anyone is ever interested in accomplishing this task, I managed to get it working using the method proposed above.

    Create a private graphicsobject in the scene header and add it to the scene (this isnt absolutely necessary, but the other option would involve creating and destroying the object many times)

    In the graphicsscene mousemoveevent:
    Set the mouse cursor to the desired image
    When the mouse is within the bounds of a "drop" location, set the graphicsobject to the mouse cursor image and the location to the top-left pixel of the "drop" location and set the mouse cursor to no cursor
    When the mouse leaves a "drop" location, restore the image from the graphicsobject, hide it, and set it to the mouse cursor image

    In the graphicsscene mousepressevent:
    Check again to ensure mouse is within "drop" location
    Add a new object to the scene containing the mouse image
    Regardless of passing the check, restore mouse to original pointer, hide the graphicsobject (setting the pixmap to NULL generates errors on some systems, hide works across all platforms)

Similar Threads

  1. Mouse lock inside window/widget
    By carbiii in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2013, 07:47
  2. view position of mouse position in GraphicsScene
    By Raghaw in forum Qt Programming
    Replies: 2
    Last Post: 23rd August 2012, 04:46
  3. How to get the mouse's position
    By sophister in forum Qt Programming
    Replies: 2
    Last Post: 30th April 2009, 06:07
  4. Mouse position on screen
    By Nippler in forum Qt Programming
    Replies: 3
    Last Post: 7th August 2008, 14:22
  5. How to get mouse's position?
    By coralbird in forum Newbie
    Replies: 4
    Last Post: 23rd July 2006, 03:52

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.