QCustomPlot Discussion and Comments

how possible any tracer or mark on QcpCurve?Return to overview

Is there any way to put point/mark on a QCPCurve ?

Thanks in advance,

Have a look at how QCPItemTracer does it for QCPGraph. You could either create a completely new item which does what you want or you could subclass QCPItemTracer to also support QCPCurve.

I use subclas of QCPItemTracer to support for QCPCurve, it worked..

Thank you..

I had the same problem and after duplicating the entire code of QCPItemTracer (and adapting it to QCPCurve), I tried to do it the more elegant way, subclassing QCPItemTracer:


#include "qcustomplot.h"

class QCPItemTracerCurve : public QCPItemTracer
    Q_PROPERTY(QPen pen READ pen WRITE setPen)
    Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
    Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
    Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
    Q_PROPERTY(double size READ size WRITE setSize)
    Q_PROPERTY(TracerStyle style READ style WRITE setStyle)
    Q_PROPERTY(QCPCurve* curve READ curve WRITE setCurve)
    Q_PROPERTY(double curveT READ curveT WRITE setCurveT)
    Q_PROPERTY(bool interpolating READ interpolating WRITE setInterpolating)
    /// \endcond
    QCPItemTracerCurve(QCustomPlot *parentPlot);
    virtual ~QCPItemTracerCurve();

    // getters:
    QCPCurve *curve() const { return mCurve; }
    double curveT() const { return mCurveT; }

    // setters;
    void setCurve(QCPCurve *curve);
    void setCurveT(double T);
    void setCurveTFromKey(double key);

    // non-virtual methods:
    void updatePosition();

    // property members:
    QCPCurve *mCurve;
    double mCurveT;

    // Hide all these.
    // Hide all these.
    QCPGraph *graph() const { return NULL; };
    double graphKey() const { return 0; };
    void setGraph(QCPGraph *graph) { Q_UNUSED(graph); };
    void setGraphKey(double key) { Q_UNUSED(key); };


But I have a quirk: updatePosition being non-virtual in the base class, a replot triggers the updatePosition of the base class. I have to make it virtual to have everything working fine.

I'm not sure why updatePosition is not virtual in QCPItemTracer or if there's any problem in making in virtual or if I have to solve this in other ways (bets I came up with is to add calls to my own updatePosition in any method of my class that actually modifies the position).

Any advice ?



is there any of open-sourced subclass of QCPItemTracer for trace QCPCurve?
dose the next release can add in?