• 欢迎浏览“String me = Creater\忠实的资深Linux玩家;”,请文明浏览,理性发言,有侵犯你的权益请邮件我(creater@vip.qq.com).
  • 把任何的失败都当作一次尝试,不要自卑;把所有的成功都想成是一种幸运,不要自傲。
  •    4年前 (2014-04-21)  qwt 评论关闭  19 
    文章评分 0 次,平均分 0.0

    因为QwtPlotCurve里有如下定义

      enum CurveStyle
        {
            /*!Don't draw a curve. Note: This doesn't affect the symbols.*/
            NoCurve = -1,
            Lines,
            Sticks,
            Steps,
            Dots,
            UserCurve = 100
        };
    

    为了能够定制曲线,需要重载以下函数,在QwtPlotCurve里的实现为

    void QwtPlotCurve::drawCurve( QPainter *painter, int style,
        const QwtScaleMap &xMap, const QwtScaleMap &yMap,
        const QRectF &canvasRect, int from, int to ) const
    {
        switch ( style )
        {
            case Lines:
                if ( testCurveAttribute( Fitted ) )
                {
                    // we always need the complete
                    // curve for fitting
                    from = 0;
                    to = dataSize() - 1;
                }
                drawLines( painter, xMap, yMap, canvasRect, from, to );
                break;
            case Sticks:
                drawSticks( painter, xMap, yMap, canvasRect, from, to );
                break;
            case Steps:
                drawSteps( painter, xMap, yMap, canvasRect, from, to );
                break;
            case Dots:
                drawDots( painter, xMap, yMap, canvasRect, from, to );
                break;
            case NoCurve:
            default:
                break;
        }
    }

    通过CurveStyle来分发不同的画线方式,我们可以使用UserCurve来区分
    1.首先定义一个派生于QwtPlotCurve的类

    class MyCurve: public QwtPlotCurve

    2.重新定义

    virtual void drawCurve( QPainter *p, int style, const QwtScaleMap &xMap,
                                const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to ) const
        {
    
            p->setPen(pen);
            switch ( style )
            {
                case QwtPlotCurve::UserCurve:
                    drawMyCurve(p,  xMap, yMap, canvasRect, from, to);
                    break;
                default:
                     QwtPlotCurve::drawCurve(p, style, xMap, yMap,canvasRect, from, to);
                    break;
           }
        }

    3.最后重新实现drawMyCurve即可。

    至此,完美解决。

     

    除特别注明外,本站所有文章均为String me = "Creater\忠实的资深Linux玩家";原创,转载请注明出处来自http://unix8.net/home.php/3372.html

    关于
    切换注册

    登录

    忘记密码 ?

    切换登录

    注册

    扫一扫二维码分享