PDA

View Full Version : Getting Mouse position



williamjamir
2nd October 2015, 18:20
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

connect(d_picker, SIGNAL(moved(QPoint)),this,SLOT(function_b(QPoint) ));

Function B

void Plot::function_b(QPoint actualMousePosition)
{
int x = curve->closestPoint(actualMousePosition,NULL);
QPointF Position = curve->sample(x);
d_marker->setValue(Position);
this->replot();
}


Now for do two cursor using signalMapper:




signalMapper = new QSignalMapper( this );

connect( d_picker, SIGNAL(moved(QPoint)), signalMapper, SLOT(map()) );
connect( d_picker1, SIGNAL(moved(QPoint)), signalMapper, SLOT(map()) );

signalMapper->setMapping( d_picker, d_picker );

signalMapper->setMapping( d_picker1, d_picker1 );

connect( signalMapper, SIGNAL(mapped(QObject*)), this,SLOT(mover(QObject*)) );


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 ?

Uwe
5th October 2015, 07:12
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

williamjamir
8th October 2015, 19:10
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

Uwe
8th October 2015, 20:05
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