Results 1 to 8 of 8

Thread: How to disable wheelEvent for scrollbars

  1. #1
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to disable wheelEvent for scrollbars

    I currently have a QGraphicsView with a QGraphicsScene set on it. I'm currently using the wheelevent to zoom in/out. However, whenever I use the wheel it first tries to move the image up or down (respective to scrolling wheel up or down). I don't want it to move the image up or down, I only want to use the wheel for zooming. Is there a way in my wheelEvent(QWheelEvent *event) function to only state to run the zoom code, and nothing else?

    Thanks in advance.

  2. #2
    Join Date
    Oct 2006
    Posts
    18
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to disable wheelEvent for scrollbars

    Have you tried doing event->accept() at the end of your function?

  3. #3
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to disable wheelEvent for scrollbars

    I tried giving that a shot. But I think the problem might be a bit deeper. I have the two following functions:

    void form::wheelEvent(QWheelEvent *event)
    bool form::eventFilter(QObject *o, QEvent *e)

    I originally put all my event calls into the eventFilter function, but for some reason was not able to call the "e->delta()" function in the eventFilter function. So I had to put it inside the wheelEvent function in order to use "event->delta()". It seems that my eventFilter is being called prior to the wheelEvent function. But even if I put "return false" into eventFilter and "event->accept()" into wheelEvent, it doesn't seem to work. If this is unclear, feel free to ask questions and I will specify. Unfortunately I cannot paste my code because my development box is not on the internet.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to disable wheelEvent for scrollbars

    You should return true in an eventFilter() to make the event filtered out from the receiver. So if you have installed an event filter for the graphics view, return true always when the graphics view is receiving a wheel event and the graphics view never receives it. To access QWheelEvent::delta(), you need to cast the QEvent* to a QWheelEvent*.
    J-P Nurmi

  5. #5
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to disable wheelEvent for scrollbars

    Thanks guys for helping me try to solve this. I'm still having a problem though...I tried to follow your advice, maybe I didn't understand you fully, but this is what I have so far (not working). When I say it is not working, what I mean is: It will zoom (which is good), but it will first try to shift the image up or down (which is bad).

    bool ImageForm::eventFilter(QObject *o, QEvent *e)
    {
    ...
    if (o == ui.graphicsView)
    {
    if (e->type == QEvent::Wheel)
    {
    QWheelEvent *q = dynamic_cast<QWheelEvent*>(e);
    scaleView((double)2, -q->delta() / 240.0));
    // q->accept();
    return true;
    }
    }
    }

    Any ideas why it is still trying to move the picture up or down based on the wheelevent?

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to disable wheelEvent for scrollbars

    Just curious, what happens if you install the event filter on graphics view's viewport() as well?
    J-P Nurmi

  7. #7
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to disable wheelEvent for scrollbars

    I just added:

    ui.graphicsView->viewport()->installEventFilter(this);

    This had no effect...did you want me to modify the filter code also?

  8. #8
    Join Date
    Oct 2006
    Posts
    83
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to disable wheelEvent for scrollbars

    Haha, you're good! That worked! Thanks guys...the code that made it work was something like this:
    ui.graphicsView->viewport()->installEventFilter(this);

    bool ImageForm::eventFilter(QObject *o, QEvent *e)
    {
    ...
    if (o == ui.graphicsView->viewport())
    {
    if (e->type == QEvent::Wheel)
    {
    QWheelEvent *q = dynamic_cast<QWheelEvent*>(e);
    scaleView((double)2, -q->delta() / 240.0));
    // q->accept();
    return true;
    }
    }
    }

Similar Threads

  1. How can I disable the QListView Sorting?
    By darpan in forum Qt Programming
    Replies: 3
    Last Post: 27th June 2006, 10:36
  2. Disable Tab Key
    By otortos in forum Newbie
    Replies: 6
    Last Post: 25th March 2006, 16:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.