I am generating mouse wheel events but they are not having any zoom effect. What am I missing here? Here are some snippets of code:
this->installEventFilter(this); this->setFocusPolicy(Qt::StrongFocus); radarPlot->setFocus(); connect(radarPlot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel(QWheelEvent*))); void radarWidget::mouseWheel(QWheelEvent *event) // SLOT from the mouse wheel { qDebug() << __FUNCTION__ << event << ":" << event->pos() << ":" << event->pos().x() << ":" << event->pos().y() << "delta:" << event->delta(); if (event->pos().y() > radarPlot->axisRect()->bottom()) // Zoom only X radarPlot->axisRect()->setRangeZoomAxes(radarPlot->xAxis, NULL); else if (event->pos().x() < radarPlot->axisRect()->left()) // Zoom only Y radarPlot->axisRect()->setRangeZoomAxes(NULL, radarPlot->yAxis); else // Zoom both radarPlot->axisRect()->setRangeZoomAxes(radarPlot->xAxis, radarPlot->yAxis); } bool radarWidget::eventFilter(QObject * /* o */, QEvent *e) { if ( e->type() == QEvent::KeyPress ) { QKeyEvent *k = (QKeyEvent *) e; QString keyStr = QKeySequence(k->key()).toString(); if(keyStr == "+" || keyStr == "-" || keyStr == "=" || keyStr == "_") { // Get the mouse location QPoint p = this->mapFromGlobal(QCursor::pos()); p -= this->childrenRect().topLeft(); // Account for the margin // Create a fake mouse wheel event QWheelEvent *evt; if(keyStr == "+") evt = new QWheelEvent(p, 1200, 0, k->modifiers()); else if(keyStr == "=") evt = new QWheelEvent(p, 120, 0, k->modifiers()); else if(keyStr == "-") evt = new QWheelEvent(p, -120, 0, k->modifiers()); else if(keyStr == "_") evt = new QWheelEvent(p, -1200, 0, k->modifiers()); else return false; emit mouseWheel(evt); delete evt; return true; // consume event } } return false; }
As you can see, I use qDebug() in the mouse event handler so I can see that mouse wheel events are generated either by scrolling the mouse, or using the + and - keys. The thing is, when I use the +- keys, no zooming actually takes place. Here's the output from that qDebug() call:
mouseWheel QWheelEvent(QPoint(0,0) QPoint(0,120) ) : QPoint(639,255) : 639 : 255 delta: 120 mouseWheel QWheelEvent(QPoint(0,0) QPoint(0,120) ) : QPoint(639,255) : 639 : 255 delta: 120 mouseWheel QWheelEvent(QPoint(0,0) QPoint(0,120) ) : QPoint(639,255) : 639 : 255 delta: 120 mouseWheel QWheelEvent(QPoint(0,0) QPoint(0,0) ) : QPoint(650,284) : 650 : 284 delta: 120 mouseWheel QWheelEvent(QPoint(0,0) QPoint(0,0) ) : QPoint(650,284) : 650 : 284 delta: 120 mouseWheel QWheelEvent(QPoint(0,0) QPoint(0,0) ) : QPoint(650,284) : 650 : 284 delta: 120
The first three are real mouse scroll events. The last three are faked ones.
I'm using qcustomplot-1.2.1
Thanks!