View Full Version : Qwt question
baray98
24th November 2007, 00:34
I have some data in my app using Qwt Plot and i want to measure some delta values using my mouse in my plot.
eg:
given:
point 1 (1,3)
point 2 (2,4)
point 3 (3,1)
now if i point my mouse to point 1 (click) then point 2 (click)
then i should show:
delta x = 1 and delta y = 1
how can i implement this in Qwt? please enlightened me
baray98
Uwe
24th November 2007, 09:03
Have a look at the CanvasPicker class in the event_filter example. It shows how to find a point from a mouse click. But note, that the implementation is slow for curves with many points.
But if I had to implement a distance measurement I would use a tailored QwtPlotPicker object, because of its tracker text.
Uwe
baray98
25th November 2007, 17:49
Hi uwe,
I did follow your advise and pop up a widget showing my delta at the end of my selction
I connected signal QwtPlotPicker::selected(const QwtDoubleRect &) to trigger my class to display the delta.
I wanted to modify this ,instead of showing delta at the end of my selecetion I want to show the delta while the user is dragging a selection , its like overiding the the tracker text how can i do this? i tried re-implementing the trackerText but did not work .
baray98
Uwe
26th November 2007, 20:31
I found some old code on my disk, maybe it helps:
class DistancePicker : public QwtPlotPicker
{
public:
DistancePicker(QwtPlotCanvas *);
protected:
virtual void drawRubberBand(QPainter *) const;
virtual QwtText trackerText(const QwtDoublePoint &) const;
};
DistancePicker::DistancePicker(QwtPlotCanvas* canvas):
QwtPlotPicker(canvas)
{
/*
We don't have a picker for a line, but the rectangle
selection is also a selection of 2 points. So all we
have to do is to paint a line rubberband.
*/
setSelectionFlags(QwtPicker::RectSelection);
setRubberBand(PolygonRubberBand);
setTrackerMode(QwtPicker::ActiveOnly);
// Disable keyboard handling
setKeyPattern(QwtEventPattern::KeySelect1, Qt::Key_unknown);
setKeyPattern(QwtEventPattern::KeySelect2, Qt::Key_unknown);
}
void DistancePicker::drawRubberBand(QPainter *painter) const
{
painter->drawPolygon(selection());
}
QwtText DistancePicker::trackerText(const QwtDoublePoint &) const
{
const QwtPolygon &polygon = selection();
if ( polygon.size() != 2 )
return QwtText();
const QLineF line(invTransform(polygon[0]), invTransform(polygon[1]));
QwtText text( QString::number(line.length()) );
QColor bg(Qt::white);
bg.setAlpha(180);
text.setBackgroundBrush(QBrush(bg));
return text;
}
Uwe
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.