QCustomPlot Discussion and Comments

problem with mousePressEvent on inherited QCPGraphReturn to overview

Hello everybody

I need to have a graph where I can get the key and value of a point by clicking on it. (and then process that in some way)
I read about the data selection mechanism here
https://www.qcustomplot.com/documentation/dataselection.html

and used the snippet given there at the bottom to inherit from QCPGraph and implement myself the mousePressEvent() (class called QCPSequenceData)

here's my code:

   
void QCPSequenceData::mousePressEvent(QMouseEvent *event, const QVariant& arg_details)
{
//first get the key and value of the clicked data point !
    double T=0; double L = 0;
    QCPGraphDataContainer::const_iterator it = data()->constEnd();
    QVariant details;
    if (selectTest(event->localPos(), false, &details))
    {
        QCPDataSelection dataPoints = details.value<QCPDataSelection>();
        if (dataPoints.dataPointCount() > 0)
        {
            it = data()->at(dataPoints.dataRange().begin());
            T = it->key;       //Timestamp
            L = it->value;     //Level
            std::cout << "T = " << T << ", L = " << L << std::endl;
        }
    }
}

just to plot the coordinate first. I didn't add much to the snippet !

the result is that it works only with clicks at a certain distance above the data point which is a circle (i set it to QCPScatterStyle(QCPScatterStyle::ssCircle, 5)). Inside the circle i.e. very close or "on" the graph point, it seems that the mousePressEvent is just not called.

I was wondering if I was missing something or if there is a bug somewhere.

any idea ?

I just read that there is this plottableClick signal that I could also use as an alternative solution but it'd be great to solve this!

ok nevermind, kind of: I figured it out, at least partially, after a couple hours of trying and reading stuff. It had to do with the range and some kind of margin.

my clickable point where at Y=0 and my Y axis range was [-0.1;1.1]. somehow if I give more room to the range below 0 it starts working inside the circle (even though they were not clipped or something)

if anybody can give me more insight as to exactly what is the issue, that would be welcome :-)

The x axis is probably capturing the click event?

oh right. I think that makes sense! thanks

so just for the challenge in case I wanted to prevent (which I won't do for now) the x axis from getting the events instead of data points, how should I go about it ?
also inherit QCPAxis, reimplement its mousePressEvent and ignore the event there and propagate it somehow to the QCPGraph ? would this be any good ?

Do you want to click on an exact data point?

well on a data point within the selection tolerance.

i was wondering how to avoid the x axis from getting the event when the data points are too close from this x axis and this axis "steals" the click events from the data points

you need use event->accept(), otherwhise qcustomplot will post event next layerable