Results 1 to 4 of 4

Thread: Getting Mouse position

  1. #1
    Join Date
    Sep 2015
    Posts
    3
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Getting Mouse position

    Hello,

    I'm trying to do two movable cursors, I already get one done however I'm having problems for the second one.

    I read an old post suggesting to use signalMapper.

    So my code for one cursor stay in this way:

    Connection
    Qt Code:
    1. connect(d_picker, SIGNAL(moved(QPoint)),this,SLOT(function_b(QPoint)));
    To copy to clipboard, switch view to plain text mode 

    Function B
    Qt Code:
    1. void Plot::function_b(QPoint actualMousePosition)
    2. {
    3. int x = curve->closestPoint(actualMousePosition,NULL);
    4. QPointF Position = curve->sample(x);
    5. d_marker->setValue(Position);
    6. this->replot();
    7. }
    To copy to clipboard, switch view to plain text mode 


    Now for do two cursor using signalMapper:

    Qt Code:
    1. signalMapper = new QSignalMapper( this );
    2.  
    3. connect( d_picker, SIGNAL(moved(QPoint)), signalMapper, SLOT(map()) );
    4. connect( d_picker1, SIGNAL(moved(QPoint)), signalMapper, SLOT(map()) );
    5.  
    6. signalMapper->setMapping( d_picker, d_picker );
    7.  
    8. signalMapper->setMapping( d_picker1, d_picker1 );
    9.  
    10. connect( signalMapper, SIGNAL(mapped(QObject*)), this,SLOT(mover(QObject*)) );
    To copy to clipboard, switch view to plain text mode 


    My question is, how to handle the mouse position? I already tried d_picker->trackerPosition(); inside of mover but didn't work.
    And I already read old post but they was moving two cursors at same time, and I need move separately


    Someone can give some idea to how to proceed ?

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: Getting Mouse position

    Quote Originally Posted by williamjamir View Post
    My question is, how to handle the mouse position?
    And this is something you have to answer yourself - not in code, but at least on a conceptual level.
    Once you have this it will be easier to help you with how to do it.

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    williamjamir (8th October 2015)

  4. #3
    Join Date
    Sep 2015
    Posts
    3
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: Getting Mouse position

    I solved my problem by re-using the code to move one marker.

    Inside of the function_b I took the value from the marker and compare it with the position of the mouse that came from the SIGNAL moved.
    To transform the Pixel position of the mouse to coordinate I used QwtScaleMap.

    I hope that this can be helpful for someone.

    Thank you Uwe for your assistance and time

  5. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: Getting Mouse position

    I wouldn't recommend using a marker - at least not, when having a heavy plot. Using a widget overlay ( like in the curve tracker example ) is more perfomant as it doesn't initiate replots, when the position of the cursor is changing.

    Uwe

Similar Threads

  1. Mouse position
    By nomad.007 in forum Newbie
    Replies: 2
    Last Post: 8th September 2015, 17:11
  2. Invert Mouse Position
    By carloval in forum Newbie
    Replies: 0
    Last Post: 21st July 2015, 06:48
  3. view position of mouse position in GraphicsScene
    By Raghaw in forum Qt Programming
    Replies: 2
    Last Post: 23rd August 2012, 05:46
  4. How to get the mouse's position
    By sophister in forum Qt Programming
    Replies: 2
    Last Post: 30th April 2009, 07:07
  5. How to get mouse's position?
    By coralbird in forum Newbie
    Replies: 4
    Last Post: 23rd July 2006, 04: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
  •  
Qt is a trademark of The Qt Company.