I found some old code on my disk, maybe it helps:
{
public:
protected:
virtual void drawRubberBand
(QPainter *) const;
virtual QwtText trackerText
(const QwtDoublePoint
&) const;
};
{
/*
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.
*/
setRubberBand(PolygonRubberBand);
// Disable keyboard handling
}
void DistancePicker
::drawRubberBand(QPainter *painter
) const {
painter->drawPolygon(selection());
}
QwtText DistancePicker
::trackerText(const QwtDoublePoint
&) const {
const QwtPolygon &polygon = selection();
if ( polygon.size() != 2 )
const QLineF line
(invTransform
(polygon
[0]), invTransform
(polygon
[1]));
bg.setAlpha(180);
text.
setBackgroundBrush(QBrush(bg
));
return text;
}
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;
}
To copy to clipboard, switch view to plain text mode
Uwe
Bookmarks