QCustomPlot Discussion and Comments

How to implement draggable QCPItemTracer Return to overview

Please tell me the best way (or any way) to implement draggable QCPItemTracer.
I want to move QCPItemTracer on its QCPGraph.

The simplest approach is to reimplement the protected slots mousePressEvent mouseMoveEvent and mouseReleaseEvent.

I've not tested to following code, but it should work.

void YourClass::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) {
    double x = clipAxisRect()->axis(QCPAxis::atBottom)->pixelToCoord(event->pos().x());
    double y = clipAxisRect()->axis(QCPAxis::atLeft)->pixelToCoord(event->pos().y());
    position->setCoords(x, y);
    layer()->replot();
}


void YourClass::mousePressEvent(QMouseEvent *event, const QVariant &details) {
}

void YourClass::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) {
}

Vincent