PDA

View Full Version : QwtPlotPicker::trackertex for labels in qwtplot problem



hamid ghous
14th April 2010, 15:55
Hi,

I am using QwtPlotPicker::trackertex for showing labels on points. I have setTrackerMode(AlwaysOn); I can easily display x and y values but what I am looking for, is to display special label for each point.
what I am trying to do in following code is...after getting x axis and y axis I wants to search for xaxis value in vector of x values and yaxis value in vector of y values and if the xaxis value and yaxis value matches any value in vector x and vector y then I will use index to retrieve the label for that position from another vector.
Its not giving me any error with this code but also not showing me desired labels.


#define EPS 1.0e-6 //tolerance for comparing double values
xaxis=pos1.x();
yaxis=pos1.y();
int size=vec_xaxisvalues.size();
for(int index=0;index<size;index++)
{

if ((vec_xaxisvalues[index]-xaxis)<EPS && (vec_yaxisvalues[index]-yaxis)<EPS)

{
//QwtText text( QwtPlotPicker::trackerText(pos1));
text.setText("good");
return text;
}

else
{
return QwtText();
}
}



Thanks in advance.

Cheers,

Uwe
15th April 2010, 06:57
You have to translate your values into widget coordinates ( = pixel positions ) and compare them with the mouse position also in widget coordinates.

Don't forget, that a screen is only a raster device !

Uwe

hamid ghous
15th April 2010, 10:16
Hi Uwe,

Thanks for the reply. I actually did it here is what I did...

#define EPS 1.0e-4
QPoint p;
QPoint p1;
p1=QwtPlotPicker::transform(pos1);
const double xaxis=p1.x();
const double yaxis=p1.y();
for(int i=0;i<size;i++)
{
QwtDoublePoint qwtdp(vec_xaxisvalues[i],vec_yaxisvalues[i]);
p=QwtPlotPicker::transform(qwtdp);
if ((p.x()-xaxis)<EPS && (p.y()-yaxis)<EPS)

{
text.setText("good");
return text;
}
But still its not showing me anything on plot...unless I increase my EPS value to really big like 1.0e10 then whole plot shows me "good"

I would really appreciate your help.

Cheers,

Uwe
15th April 2010, 11:34
#define EPS 1.0e-4
This value is the acceptable radius around the position of a translated point in screen geometries ( = number of pixels ). An integer between 0-5 might be useful but something like 1.0e-4 makes no sense.

Overload QwtPlotPicker::trackerText(const QPoint &) instead of QwtPlotPicker::trackerText(const QwtDoublePoint &) and remove the first transformation. The rest of your code snippet looks o.k for me - assuming, that pos1 is the parameter you got from QwtPlotPicker::trackerText(const QwtDoublePoint &).

Before you post the next time I recommend to insert a qDebug statement printing the mouse position and one of your transformed curve points to see if they are in the same coordinate system.

Uwe

hamid ghous
15th April 2010, 14:27
I got your point about EPS 1.0-e4 after seeing the transform values I also did the changes you mentioned earlier but still the result is the same its showing me label everywhere on plot...
Here is the transform value and Mouse position..
Mouse position is: 15,159 Transform values are:17,42

Cheers,

hamid ghous
15th April 2010, 14:28
sorry forgot to mention ...pos1 is the parameter or position I am getting from QwtPlotPicker::trackerText(const QPoint &) now..

Uwe
15th April 2010, 14:48
Here is the transform value and Mouse position..
Mouse position is: 15,159 Transform values are:17,42
At least both look like reasonable positions now. The x coordinate seems to match, but the y coordinate not: 42 means your point is 42 pixels below the top border of the canvas.

- Assuming your mouse is over the point: which value (42 or 159) is wrong ?
- What is the geometry of the canvas ( is one of the y values the distance from the bottom ? )
- Is the picker attached to the same y axis as your curve ?

Uwe

hamid ghous
16th April 2010, 16:49
Hi Uwe,

I just figured out the problem was for loop so I just removed the loop out of the program and used distance function of vectors to get the index of the value and now its showing me the labels (problem solved)...but as I am showing label on the basis of pixel coordinates so its really hard to see the label cursor has to be on exact pixel coordinates. I am using Xcross as symbol. Is there any way that I can see label whenever cursor comes to the symbol.
Also how can I perform zooming with pixel coordinates?

I really appreciate your help.

Cheers,

Uwe
16th April 2010, 19:02
but as I am showing label on the basis of pixel coordinates so its really hard to see the label cursor has to be on exact pixel coordinates.
?????



I am using Xcross as symbol. Is there any way that I can see label whenever cursor comes to the symbol.
Setting EPS to 0.5 + symbol.size and you will have matches for the bounding rectangle of the cross. If you need exact compares with the shape of a symbol you could paint the symbol on a bitmap translate its center to the mapped curve point and compare the mouse position with the corresponding bit.


Also how can I perform zooming with pixel coordinates?
The only thing that need to be done in pixel coordinates is the point matching algo. I don't see a reason to do anything else in pixel coordinates.

Your code should be like this:


virtual QwtText YourPicker::trackerText(const QPoint &pos) const
{
QwtText text;
if ( isNearToACurvePoint(pos) );
text = QwtPlotPicker::trackerText(pos);

return text;
}
Uwe

hamid ghous
17th April 2010, 05:01
Thanks Uwe for your help..

hamid ghous
19th April 2010, 15:54
Hi Uwe,

Here is what I was trying to say about zooming; I was performing simple zooming by using following code:

I am not after complicated zooming just the simple one.


QwtPlotZoomer *zoomer;
zoomer= new QwtPlotZoomer(QwtPlot::xBottom,QwtPlot::yRight,myP lot->canvas());
zoomer->setTrackerMode(QwtPicker::AlwaysOff);



But Now when I zoom in,it doesn't show me the label on the point. Any idea how can I do it...

Regards,

Uwe
20th April 2010, 06:03
Read this thread and do the same for your zoomer ( QwtPlotZoomer is derived from QwtPlotPicker ).

Uwe

hamid ghous
20th April 2010, 06:58
Where is this thread?

Uwe
20th April 2010, 08:23
It starts at the beginning of this page and ends at the bottom - are you serious ?

Uwe

hamid ghous
20th April 2010, 11:40
Oh sorry I thought may be you were saying the thread title is ( QwtPlotZoomer is derived from QwtPlotPicker )