QCustomPlot Discussion and Comments

Add zero-cursor for each graph on y-axisReturn to overview

Hi everyone,
I need to put a cursor that indicate the 0 of the graph. This cursor should be tied with the axis of the specific graph.
I tried QPixmapItem and it seems to work, but the pixmap will be placed into the graph and if I scroll (vertically or horizontally) the graph, pixmap is tied with the plot area (AxisRect).
This is my code (into MainWindow constructor):

	QPixmap p;
	p.load("://resources/pixmap/cursor0.png");
	zeroCursor = new QCPItemPixmap(ui->Plot);
	zeroCursor->setPixmap(p);
	zeroCursor->setClipAxisRect(ui->Plot->axisRect(0)->axis(QCPAxis::atLeft,2)->axisRect());
	zeroCursor->setClipToAxisRect(false);
	zeroCursor->topLeft->setCoords(0,0);

On the contrary, I would like a pixmap fixed with the vertical axis, something like this: https://postimg.org/image/3t2klt4lr/

Moreover, according to some forum post, I tried to add a new layer too, but it didn't work: this error occurs "bool QCustomPlot::addLayer(const QString&, QCPLayer*, QCustomPlot::LayerInsertMode) otherLayer not a layer of this QCustomPlot"

What is the best way to do add a cursor on y-axis bound with each waveform?

Thanks
Calzo

v2.0.0.beta, QT 5.7

i believe you are looking for QCPItemPosition::PositionType.

in your code, it would be zeroCursor->topLeft->setTypeY(QCPItemPosition::ptViewportRatio) ... or ptAbsolute...or ptAxisRectRatio... basically anything other than ptPlotCoords

this would make the y value lock to pixels, viewport or axis instead of locking to the coordinate of zero. i'm assuming you still want the x position to lock to the coordinate you place the marker at, so you would keep that as ptPlotCoords.

Thanks Ian,

this works fine. For my application the best choice seems to be for both X and Y: zeroCursor->topLeft->setType(QCPItemPosition::ptAbsolute);

Regards.
Calzo