如何在QwtPlot上为QwtPlotCurve添加标签?

时间:2015-05-07 07:24:46

标签: c++ qt qwt

如何在QwtPlot上为QwtPlotCurve添加标签? enter image description here

例如

1 个答案:

答案 0 :(得分:1)

我的解决方案

class QwtPlotCurveWithTitle : public QwtPlotCurve{
public:
    explicit QwtPlotCurveWithTitle( const QString &title = QString::null ) : QwtPlotCurve(title){}
    explicit QwtPlotCurveWithTitle( const QwtText &title ) : QwtPlotCurve(title){}
protected:
    virtual void drawCurve( QPainter *p, int style,
        const QwtScaleMap &xMap, const QwtScaleMap &yMap,
        const QRectF &canvasRect, int from, int to ) const{
        QwtPlotCurve::drawCurve(p,style,xMap,yMap,canvasRect,from,to);
        QPointF point = sample(from);
        p->drawText(xMap.transform(point.x()),yMap.transform(point.y()),title().text());
    }
};