QCustomPlot Discussion and Comments

QCPItemLine not drawn in mouseMove eventReturn to overview

I try to get a vertical position line drawn on a simple class derived from QCustomPlot, which shows a simple graph. The graph plots and zooms/resizes correctly. The plot widget was added directly to a QDockWidget.

Then, I tried to draw a vertical position line over the graph that follows the current position of the mouse.
I did the following:

In the constructor of my QCustomPlot derived class, I add:

m_markerLine = new QCPItemLine(this);

Then, in the mouseMoveEvent reimplementation, i added:

void MyPlot::mouseMoveEvent(QMouseEvent *event)
        double ystart = yAxis->range().lower;
        double yend = yAxis->range().upper;
        double key = xAxis->pixelToCoord(event->x());

        m_markerLine->start->setCoords(key, ystart);
        m_markerLine->end->setCoords(key, yend);

However, this does not work. The line does not show, until I click (but even when clicking, it does not always appear immediately). In any case, the line does not follow the mouse x position, or is not visible.
The mouse move handler is entered correctly, as debug messages printed therein work.

What am I doing wrong?


I needed to add


in mouseMoveEvent...