Catch mouse event when clicked on the axis of a qchart diagram

1k Views Asked by At

I'm programming an app. in QT c++ and have the following question: Is it possible to catch a mouse event when clicked on the axes(not in the diagram itself) of the qchart diagram?

I have tried to overwrite the event method of the axes instance, but the event method is not called..

I also tried to solve the problem with an eventfilter on the QChart instance, the eventfilter works so far. But how to distinguish the mouseclick between the Axis and Qchart area itself?

//Mouse filter Object:
MousePressEater::MousePressEater(Axes* ax)
{
    this->axis = ax;
}

bool MousePressEater::eventFilter(QObject *obj, QEvent *event)
{
    //qDebug() << event->type();
    if (event->type() == QEvent::UngrabMouse) {
        QMouseEvent *mEvent = static_cast<QMouseEvent *>(event);
        qDebug("Ate mouse press %d %d %d %d", mEvent->pos().x() , mEvent->pos().y() , axis , obj );
        return true;
    } else {
        // standard event processing
        return QObject::eventFilter(obj, event);
    }
}


//Installing the filter in the constructor(inherited from QChart):
MousePressEater *mPressEater = new MousePressEater(ax);
this->installEventFilter(mPressEater);

"obj" just gives back a pointer to the QChart instance if clicked on the axis.

Anybody has a solution for this problem? Thanks!

1

There are 1 best solutions below

0
On

Please check documentation for *QObject::installEventFilter(QObject filterObj) and *void QWidget::mousePressEvent(QMouseEvent event)