Results 1 to 3 of 3

Thread: Place Item At Mouse Coordinates?

  1. #1
    Join Date
    Oct 2012
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Place Item At Mouse Coordinates?

    Hello,

    Thanks for the amount of support I have received on this forum so far, it is much appreciated as I have not used C++ for some time. Thanks to wysota, I have figured out custom classes and figured out a lot of my problems. I have run into another pretty simple problem and I was wondering if someone could help me out or point me in the right direction - When a user clicks on my graphics scene I would like it to place a blue square at the mouse position. How would I go about doing this?

    I have the code for drawing the square but I do not have the code to place it at the mouse-coordinates.

    Thanks in advance guys,
    Matt

  2. #2

    Default Re: Place Item At Mouse Coordinates?

    Check out QWidget::cursor() ,which returns QCursor and you can get .pos() from that. Also, you will probably have to look at QWidget::mapToGlobal() and/or QWidget::mapFromGlobal().

  3. #3
    Join Date
    Oct 2012
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Place Item At Mouse Coordinates?

    Hey Man, Thanks sooo much, I cannot begin to describe how much closer you have brought me to completing this. This works, however, the position is slightly off although this is more than likely because I need to look more into the mapFromGlobal()

    Thanks,
    Matt

  4. The following user says thank you to steadi for this useful post:


Similar Threads

  1. Replies: 5
    Last Post: 3rd March 2016, 16:42
  2. tracking mouse coordinates
    By lightning2911 in forum Newbie
    Replies: 8
    Last Post: 12th December 2011, 00:51
  3. how to get mouse coordinates from Qgraphicsview
    By ready in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2011, 06:33
  4. Place Plot marks on mouse click event
    By maybe78 in forum Qwt
    Replies: 2
    Last Post: 19th November 2009, 13:16
  5. getting mouse coordinates
    By eric in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 20:34

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.