Solved How can I ignore horizontally QWheelEvent?(for mouse pad)
-
I use QWheelEvent for zoom in/out on GraphicsScene but the problem is that zoom in/out is also working when I use mouse pad horizontally. I want to ignore this situation. I want to do zoom in/out on mouse pad just vertically.
My code is:
void WheeledGraphicsView::wheelEvent(QWheelEvent *event){ setTransformationAnchor(QGraphicsView::AnchorUnderMouse); double scaleFactor = 1.15; if(event->delta() > 0) { scale(scaleFactor, scaleFactor); } else { scale(1.0 / scaleFactor, 1.0 / scaleFactor); } // QWheelEvent.orientation(); }
maybe I can use QWheelEvent::orientation() but I couldn't use it. thank you !
-
Hi and welcome
code shows
// QWheelEvent.orientation();but I assume you did mean
event->orientation(); ?
Why cant you use it ?
-
@mrjj Hi,
actually I don't understand how can I ignore horizontally wheelevent using QWheelEvent::orientation(). So I couldn't it bcs of I don't understand.
thank you.
-
@ardaozdemir
ok.Can you check if its different for horizontally versus vertically "wheeling"
?just qDebug() the value
-
okey I solved the problem.
void WheeledGraphicsView::wheelEvent(QWheelEvent *event){ if(event->orientation() == Qt::Horizontal) { event->ignore(); } else { if(event->delta() > 0) { scale(ZOOM_RATIO_PER_WHEEL_TICK, ZOOM_RATIO_PER_WHEEL_TICK); } else { scale(1.0 / ZOOM_RATIO_PER_WHEEL_TICK, 1.0 / ZOOM_RATIO_PER_WHEEL_TICK); } } }
thank you.
-
So I assume it did have the right value :)
please mark as solved if possible.