PDA

View Full Version : Scrolling on Mouse Wheel



penny
6th April 2011, 12:17
I have an application, where i've enabled zooming on Ctrl+Mousewheel, using the following code
void GraphWidget::wheelEvent(QWheelEvent *event)

{
if (event->modifiers().testFlag(Qt::ControlModifier))
{
scaleView(pow((double)2, -event->delta() / 240.0));
}
}
However, i also want the scrollbars to respond to wheelevents when mouse wheel is moved without Ctrl being pressed. How do i do that ?

JohannesMunk
6th April 2011, 12:24
You want the default implementation to work? Then you need to call the inherited wheelEvent, when you don't handle the event yourself.

HIH

Joh

penny
6th April 2011, 13:03
Thanks for the reply.
How do i call the default wheelevent? Isn't it called automatically when i move the mouse wheel?

JohannesMunk
6th April 2011, 13:11
You need to call the base class implementation. Otherwise you are overriding its functionality. Your GraphWidget inherits from QGraphicsView?

Then it would look like this:


void GraphWidget::wheelEvent(QWheelEvent *event)
{
if (event->modifiers().testFlag(Qt::ControlModifier))
{
scaleView(pow((double)2, -event->delta() / 240.0));
} else {
QGraphicsView::wheelEvent(event);
}
}

HIH

Johannes

penny
7th April 2011, 08:30
Thank you so much!! It works properly now..