Results 1 to 5 of 5

Thread: Scrolling on Mouse Wheel

  1. #1
    Join Date
    Dec 2010
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Scrolling on Mouse Wheel

    I have an application, where i've enabled zooming on Ctrl+Mousewheel, using the following code
    void GraphWidget::wheelEvent(QWheelEvent *event)
    Qt Code:
    1. {
    2. if (event->modifiers().testFlag(Qt::ControlModifier))
    3. {
    4. scaleView(pow((double)2, -event->delta() / 240.0));
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 
    However, i also want the scrollbars to respond to wheelevents when mouse wheel is moved without Ctrl being pressed. How do i do that ?

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scrolling on Mouse Wheel

    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

  3. #3
    Join Date
    Dec 2010
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Scrolling on Mouse Wheel

    Thanks for the reply.
    How do i call the default wheelevent? Isn't it called automatically when i move the mouse wheel?

  4. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scrolling on Mouse Wheel

    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:

    Qt Code:
    1. void GraphWidget::wheelEvent(QWheelEvent *event)
    2. {
    3. if (event->modifiers().testFlag(Qt::ControlModifier))
    4. {
    5. scaleView(pow((double)2, -event->delta() / 240.0));
    6. } else {
    7. QGraphicsView::wheelEvent(event);
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    HIH

    Johannes

  5. The following user says thank you to JohannesMunk for this useful post:

    penny (7th April 2011)

  6. #5
    Join Date
    Dec 2010
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Scrolling on Mouse Wheel

    Thank you so much!! It works properly now..

Similar Threads

  1. QDial disabling key scroll and mouse wheel scroll
    By ldg20 in forum Qt Programming
    Replies: 2
    Last Post: 2nd June 2010, 23:05
  2. Replies: 3
    Last Post: 9th March 2010, 09:37
  3. combining wheel events
    By mcarter in forum Qt Programming
    Replies: 1
    Last Post: 13th January 2010, 05:59
  4. wheel event problem
    By bhogasena in forum Qt Programming
    Replies: 1
    Last Post: 30th January 2009, 19:11
  5. Wheel and QTest
    By skrzypu in forum Qt Programming
    Replies: 1
    Last Post: 12th May 2008, 20:05

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.