PDA

View Full Version : Need to implement 2 grabbable cursors(markers)



MrGarbage
9th January 2008, 16:44
I will be needing to implement 2 cursors (markers) in my graph. One should be able to grab
and move each of the 2 cursors with a deltaX, deltaY being displayed somewhere that
shows the difference between cursor1 and cursor 2.

This seems like functionality that someone would have already done, so before I start to reinvent the wheel, are there any examples of similar functionality out there?

If not any suggestions on how to best approach it?

Thank you.

Mark

Uwe
11th January 2008, 10:59
Something like this ?


class DistancePicker : public QwtPlotPicker
{
public:
DistancePicker( QwtPlotCanvas*);

protected:
virtual void drawRubberBand(QPainter*) const;
virtual QwtText trackerText(const QwtDoublePoint& pos) const;
};

DistancePicker::DistancePicker(QwtPlotCanvas* canvas):
QwtPlotPicker(canvas),
{
/*
We don't have a picker for a line, but the rectangle
selection is also selection of 2 points, so all we
have to do is to change the rubberband.
*/
setSelectionFlags(QwtPicker::RectSelection);
setRubberBand(PolygonRubberBand);
setTrackerMode(QwtPicker::ActiveOnly);
}

void DistancePicker::drawRubberBand(QPainter *painter) const
{
painter->drawPolygon(selection());
}

QwtText DistancePicker::trackerText(const QwtDoublePoint &pos) const
{
QwtText text( " selection() as distance string " );

QColor bg(Qt::white);
bg.setAlpha(180);
text.setBackgroundBrush(QBrush(bg));
return text;
}